标签:
#coding=utf-8 from django.shortcuts import render from django.template.loader import get_template from django.template import Context import datetime #import sys #reload(sys) #sys.setdefaultencoding(‘cp936‘) # Create your views here. from django.shortcuts import render,render_to_response from django.http import HttpResponse # Create your views here. a="测试" def hello(request): return HttpResponse(a) def current_datetime(request): now = datetime.datetime.now() t = get_template(‘current_datetime.html‘) html = t.render(Context({‘current_date‘: now})) return HttpResponse(html)
其中current_datetime.html就是我们要使用的模板,可以自己添加好多效果,基本内容为
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="Generator" content="EditPlus®"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <title>Document</title> </head> <body> it is now {{ current_date }} </body> </html>
from django.conf.urls import patterns, include, url from django.contrib import admin from views.views import hello from views.views import current_datetime urlpatterns = 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), )
TEMPLATE_DIRS=( os.path.join(BASE_DIR,‘templates‘),)
问题解决
如何定位basedir呢?我用的笨办法,setting.py中有一句配置:‘NAME‘: os.path.join(BASE_DIR, ‘db.sqlite3‘),
我把db.sqlite3的目录给找出来了
应该还有别的办法,欢迎探讨,下期研究数据库或auth认证。
windows下django1.7 +python3.4.2搭建记录2
标签:
原文地址:http://www.cnblogs.com/slqt/p/4319138.html