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 ...
随机推荐
- [iOS]利用通知实现监听系统键盘
// // ViewController.m // text // // Created by 李东旭 on 16/1/22. // Copyright © 2016年 李东旭. All rights ...
- Linux命令(3):wc命令
Linux系统中的wc(Word Count)命令的功能为统计指定文件中的字节数.字数.行数,并将统计结果显示输出. 1.命令格式: wc [选项]文件... 2.命令功能: 统计指定文件中的字节数. ...
- python流程控制语句 ifelse - 4
嵌套 #! /usr/bin/python a = int(input ("请输入一个整数:")) : : print ("无法显示") else : prin ...
- bootrom启动流程【转】
转自:http://blog.csdn.net/blueoceanindream/article/details/6851787 闲来无事,总结一下linux bootrom的启动流程: 环境:MIP ...
- U3D NGUI改变GameObject Activity闪烁的问题
不是关闭再激活GameObject会闪烁,而是再激活时,NGUI渲染步骤不一致导致的闪烁. 并且文字激活后渲染要慢一帧,如果延迟一帧处理,又会导致精灵图片快一帧,图片重叠.这个测试结果不一定准确,先记 ...
- Android Touch(1)事件的传递流程(*)
1,Activity,ViewGroup,View的关系 2,触摸事件 3,传递事件时的重要函数 4,事件传递流程参考图 5,其它参考资料 1,Activity,ViewGroup,View的关系 本 ...
- MSAA, UIA brief explanation
MSAA, UIA brief explanation 2014-07-24 Reference [1] MSAA, UIA brief explanation [2] Testing Tools [ ...
- leetcode:Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
- 配置Tomcat 中文字符集问题
找到Tomcat安装路径下的conf文件夹下的server.xml配置文件,修改配置Tomcat端口的标签"Connector",添加URIEncoding属性,代码如下: < ...
- POJ 3107 Godfather (树形dp)
题目链接 虽然题目不难,但是1A还是很爽, 只是刚开始理解错题意了,想了好久. 还有据说这个题用vector会超时,看了以后还是用邻接吧. 题意: 给一颗树,保证是一颗树,求去掉一个点以后的联通块里节 ...