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 ...
随机推荐
- 我们为什么需要DTO(数据传输对象)
原文:http://www.cnblogs.com/Gyoung/archive/2013/03/23/2977233.html DTO即数据传输对象(Data Transfer Object).之前 ...
- Data Flow ->> Script Component
和Control Flow中的Script Task非常类似,不同的是Script Component是Per-Row的执行类型.打个比方,在Script Component中加入两个Output的字 ...
- PHP 增删改查 import!!
主页面 <h1>主页面family</h1> <table width="100%" border="1px" cellpaddi ...
- Java 异常 —— java.io.InvalidClassException: javax.xml.namespace.QName; local class incompatible
项目中有个 WebService 接口,调试时使用 Main 方法运行,别人的机器上都能运行,就笔者的机器出问题.他们说是RP的问题…… 异常信息: java.io.InvalidClassExcep ...
- TFSAPI
Team Foundation Server (TFS)工具的亮点之一是管理日常工作项, 工作项如Bug, Task,Task Case等. 使用TFS API编程访问TFS服务器中的工作项, 步骤如 ...
- Python Mongo操作
# -*- coding: utf-8 -*- ''' Python Mongo操作Demo Done: ''' from pymongo import MongoClient conn = None ...
- cocos2dx Android 环境搭建 以及 ndk调试
最近在学习cocos2dx,真的很强大,使我们更专注于游戏趣味,免去了繁琐的底层框架代码. cocos2dx的最强大之处当然在于跨平台.跨平台首选当然是Android,好记性不如烂笔头,记下本文分享给 ...
- some resource favor
http://www.moxiemanager.com/getit/ : picture file manage with blur 可以和Tinymce结合使用完美实现WYSIWYG的效果 http ...
- UVa 101 The Blocks Problem
题意:给出从左到右放置的n块木块(从0开始编号),再给出四种操作,再给出相应的操作,输出操作结束后每一堆木块的情况. 学习的紫书,因为每一堆的木块数是在发生变化的,所以用vector. 然后就是模拟几 ...
- (转)FirstResponder 释放问题
FirstResponder 释放问题 转自:http://www.cnblogs.com/smileEvday/archive/2012/03/18/2405190.html View的FirstR ...