windows下django1.7 +python3.4.2搭建记录2
写一个显示当前时间的页面
views.py文件加一个使用模板的模块,整体内容为:
#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>
其中current_date就是相当于一个数据转换的精确开关
urls.py内容自然也要添加模块绑定的语句
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),
)
做完这些,浏览器里输入http://127.0.0.1:8000/current_datetime/,会报错
TemplateDoesNotExist at /current_datetime/
其中有句话是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)
很明显模板文件应该放在这两个文件夹的其中一个下,于是移动文件
然后我们在settings.py里添加这么一句,必须放在base_dir后方:
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的更多相关文章
- windows下django1.7 +python3.4.2搭建记录1
python+django在linux下搭建比较简单,windows下搭建比较复杂,所以列在下方一.下载安装下载django的包,到刚解压后的Django-1.7目录下执行命令 python setu ...
- Windows下Python2与Python3两个版本共存的方法详解
来源:http://www.jb51.net/article/105311.htm 这篇文章主要介绍了Windows下Python2与Python3两个版本共存的方法,文中介绍的很详细,对大家具有一定 ...
- windows下用eclipse+goclipse插件+gdb搭建go语言开发调试环境
windows下用eclipse+goclipse插件+gdb搭建go语言开发调试环境 http://rongmayisheng.com/post/windows%E4%B8%8B%E7%94%A ...
- Qt4.8在Windows下的三种编程环境搭建
Qt4.8在Windows下的三种编程环境搭建 Qt的版本是按照不同的图形系统来划分的,目前分为四个版本:Win32版,适用于Windows平台:X11版,适合于使用了X系统的各种Linux和Unix ...
- windows下python2和python3同时安装ipython
1.ipython简介: IPython 是一个 python 的交互式 shell,比默认的python shell 好用得多,支持变量自动补全,自动缩进,支持 bash shell 命令,内置了许 ...
- Windows下基于http的git服务器搭建-gitstack
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Windows下基于http的git服务器搭建-gitstack 本文地址:http: ...
- Windows下Visual Studio2017之AI环境搭建
本博客主要包含以下3点: AI简介及本博客主要目的 环境介绍及安装原因 搭建环境及检验是否安装成功 离线模型的训练 时间分配: 时间 时长(分钟) 收集资料+写博客 6.12 11:28-12:2 ...
- Windows下Nginx+Web.py+FastCGI服务搭建
在搭建之前,有必要了解下什么是fastcgi,但鉴于我自己也不大了解,这里就不搬门弄斧了,请参考各种百科和官网资料. 1.资源下载 python下载地址:戳这里webpy下载地址:戳这里flup下载地 ...
- Windows下Nginx+Mysql+Php(wnmp)环境搭建
前言 最近想在windows下使用nginx搭建web环境,本来想用套件(WNMP)一键安装,但后来放弃了,觉得还是自己动手,丰衣足食的好,而且套件的局限性太大.所以后来就各种搜索,看到前辈写关于wn ...
随机推荐
- 【查找结构4】红黑树 [RBT]
红黑树的性质与定义 红黑树(red-black tree) 是一棵满足下述性质的二叉查找树: 1. 每一个结点要么是红色,要么是黑色. 2. 根结点是黑色的. 3. 所有叶子结点都是黑色的(实际上都是 ...
- 282. Expression Add Operators
题目: Given a string that contains only digits 0-9 and a target value, return all possibilities to add ...
- 277. Find the Celebrity
题目: Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exi ...
- Spring_MVC_教程_快速入门_深入分析
Spring MVC 教程,快速入门,深入分析 博客分类: SPRING Spring MVC 教程快速入门 资源下载: Spring_MVC_教程_快速入门_深入分析V1.1.pdf Spring ...
- 关于Linux操作系统下文件特殊权限的解释
文件特殊权限的解释. -rwsr-xr-x = 4755 文件执行的时候,会以owner的身份来执行,就是setuid . 例如:-rwxr-xr-t 1 root wheel 0 7 9 18:24 ...
- C# winform窗体假死
C# winform窗体假死 我们经常会遇到当执行一个比较大的函数时,窗体会出现假死的现象,给用户的体验不是很好,于是我们遇到了问题,那么就必须解决,我们该如何解决呢,首先在自己的脑里画个问号,接下 ...
- spring mvc 导出 excel
// js 触发导出 excel 方法 导出当前页的数据 含有条件查询的结果 // js 框架使用的 是 easyui function doExport(){ var optins = $(&quo ...
- 总结Allegro元件封装(焊盘)制作方法[修整]
总结Allegro元件封装(焊盘)制作方法 在Allegro系统中,建立一个零件(Symbol)之前,必须先建立零件的管脚(Pin).元件封装大体上分两种,表贴和直插.针对不同的封装,需要制作不同的P ...
- LCS记录路径
还想用hash记录……果然是天真.lcs转移比较简单,每次增加1.每次找是当前-1的就行了. #include <algorithm> #include <iostream> ...
- 通过外网IP访问内网
外网服务器:外网IP1,内网IP192.168.2.156 内网服务器:内网IP192.168.2.206 通过访问外网服务器8083端口,转发到内网服务器的8083端口. 在外网服务器设置映射规则: ...