1、自定义页面
写一个显示当前时间的页面
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的更多相关文章

  1. windows下django1.7 +python3.4.2搭建记录1

    python+django在linux下搭建比较简单,windows下搭建比较复杂,所以列在下方一.下载安装下载django的包,到刚解压后的Django-1.7目录下执行命令 python setu ...

  2. Windows下Python2与Python3两个版本共存的方法详解

    来源:http://www.jb51.net/article/105311.htm 这篇文章主要介绍了Windows下Python2与Python3两个版本共存的方法,文中介绍的很详细,对大家具有一定 ...

  3. windows下用eclipse+goclipse插件+gdb搭建go语言开发调试环境

    windows下用eclipse+goclipse插件+gdb搭建go语言开发调试环境   http://rongmayisheng.com/post/windows%E4%B8%8B%E7%94%A ...

  4. Qt4.8在Windows下的三种编程环境搭建

    Qt4.8在Windows下的三种编程环境搭建 Qt的版本是按照不同的图形系统来划分的,目前分为四个版本:Win32版,适用于Windows平台:X11版,适合于使用了X系统的各种Linux和Unix ...

  5. windows下python2和python3同时安装ipython

    1.ipython简介: IPython 是一个 python 的交互式 shell,比默认的python shell 好用得多,支持变量自动补全,自动缩进,支持 bash shell 命令,内置了许 ...

  6. Windows下基于http的git服务器搭建-gitstack

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Windows下基于http的git服务器搭建-gitstack     本文地址:http: ...

  7. Windows下Visual Studio2017之AI环境搭建

    本博客主要包含以下3点: AI简介及本博客主要目的 环境介绍及安装原因 搭建环境及检验是否安装成功 离线模型的训练 时间分配:   时间 时长(分钟) 收集资料+写博客 6.12 11:28-12:2 ...

  8. Windows下Nginx+Web.py+FastCGI服务搭建

    在搭建之前,有必要了解下什么是fastcgi,但鉴于我自己也不大了解,这里就不搬门弄斧了,请参考各种百科和官网资料. 1.资源下载 python下载地址:戳这里webpy下载地址:戳这里flup下载地 ...

  9. Windows下Nginx+Mysql+Php(wnmp)环境搭建

    前言 最近想在windows下使用nginx搭建web环境,本来想用套件(WNMP)一键安装,但后来放弃了,觉得还是自己动手,丰衣足食的好,而且套件的局限性太大.所以后来就各种搜索,看到前辈写关于wn ...

随机推荐

  1. 初始化glew,创建OpenGL渲染上下文

    void RegisterWinDowClass(HINSTANCE hInstance,std::string className,WNDPROC proc) { WNDCLASS wndClass ...

  2. 关于strlen

    strlen的实现是通过4个字节4个字节进行枚举,然后通过位运算来判断这4个字节中是否有一个字节含有0,这样的话,效率就提高了4倍. 这个效率提高是假设a&b&c&d与a&am ...

  3. js网页滚动条滚动事件实例分析

    本文实例讲述了js网页滚动条滚动事件用法.分享给大家供大家参考.具体分析如下: 在做js返回顶部的效果时,要监听网页滚动条滚动事件,这个事件就是:window.onscroll.当onscroll事件 ...

  4. POJ2282:The Counting Problem(数位DP)

    Description Given two integers a and b, we write the numbers between a and b, inclusive, in a list. ...

  5. Linux驱动修炼之道-RTC子系统框架与源码分析【转】

    转自:http://helloyesyes.iteye.com/blog/1072433 努力成为linux kernel hacker的人李万鹏原创作品,为梦而战.转载请标明出处 http://bl ...

  6. dojo 资源库

    文档 :http://wenku.baidu.com/link?url=Nnek_tAjIC-Q3t3e9zHQmsh4LhU3f0ncC1QH8WD_U9-I8-fJ7mMisscFpgfuS8nU ...

  7. SPOJ 2916 Can you answer these queries V(线段树-分类讨论)

    题目链接:http://www.spoj.com/problems/GSS5/ 题意:给出一个数列.每次查询最大子段和Sum[i,j],其中i和j满足x1<=i<=y1,x2<=j& ...

  8. 总结Selenium自动化测试方法(三)WebDriver定位元素方法

    三.WebDriver定位元素 推荐使用的webdriver是firefox,因为他的firebug更能可以帮助定位页面元素使用 # create a new Firefox session cls. ...

  9. cdoj 1334 郭大侠与Rabi-Ribi 贪心+数据结构

    郭大侠与Rabi-Ribi Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Su ...

  10. java生成带html样式的word文件

    参考:http://blog.csdn.net/xiexl/article/details/6652230 最近在项目中需要将通过富文本编辑器处理过的文字转换为Word,查了很久,大家通常的解决办法是 ...