Windows django1.7 +python3.4.2 build record 2

Source: Internet
Author: User
Tags auth

1. Custom page
Write a page that shows the current time
views.py file plus a module using the template, the overall content is:
#Coding=utf-8 fromDjango.shortcutsImportRender fromDjango.template.loaderImportget_template fromDjango.templateImportContextImportdatetime#Import SYS#Reload (SYS)#sys.setdefaultencoding (' cp936 ')#Create your views here. fromDjango.shortcutsImportRender,render_to_response fromDjango.httpImportHttpResponse#Create your views here.A="Test"defHello (Request):returnHttpResponse (a)defCurrent_datetime (Request): now=Datetime.datetime.now () T= Get_template ('current_datetime.html') HTML= T.render (Context ({'current_date': now})) returnHttpResponse (HTML)

Where current_datetime.html is the template we want to use, you can add a lot of effects, the basic content of

<!DOCTYPE HTML><HTMLLang= "en"> <Head>  <MetaCharSet= "UTF-8">  <Metaname= "Generator"content= "editplus®">  <Metaname= "Author"content="">  <Metaname= "Keywords"content="">  <Metaname= "Description"content="">  <title>Document</title> </Head> <Body>It's now {{current_date}}</Body></HTML>
Where current_date is the exact switch that corresponds to a data conversion
urls.py content naturally also add a module-bound statement
 fromDjango.conf.urlsImportpatterns, include, url fromDjango.contribImportAdmin fromViews.viewsImportHello fromViews.viewsImportCurrent_datetimeurlpatterns= Patterns ("',    #Examples:    #URL (r ' ^$ ', ' MyDjango.views.home ', name= ' home '),    #URL (r ' ^blog/', include (' Blog.urls ')),    #URL (r ' ^admin/', include (Admin.site.urls)),URL (r'^hello/$', hello), url (r'^current_datetime/$', Current_datetime),)
After this, the browser input http://127.0.0.1:8000/current_datetime/, will be error
Templatedoesnotexist at/current_datetime/
One of the words is using loader django.template.loaders.app_directories. Loader:
D:\Python34\lib\site-packages\django\contrib\admin\templates\current_datetime.html (File does not exist)
D:\Python34\lib\site-packages\django\contrib\auth\templates\current_datetime.html (File does not exist)
It is obvious that the template file should be placed under one of the two folders and move the file
Then we add such a sentence in the settings.py, which must be placed behind the Base_dir:
Template_dirs= (Os.path.join (Base_dir,'templates'),)

Problem solving

How to locate Basedir? I used the stupid way, setting.py has a sentence configuration:
' NAME ' ' Db.sqlite3 '),

I found the Db.sqlite3 catalogue.

There should be another way, welcome to explore, the next research database or AUTH certification.

Windows django1.7 +python3.4.2 build record 2

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.