python下的web开发框架 Django,url配置
url配置
我们在polls这个app下创建一个
helloworld.py
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, Django.")
修改 urls.py
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^newtest/', include('newtest.foo.urls')),
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^$', 'newtest.helloworld.index'),
# Uncomment the next line to enable the admin:
# (r'^admin/(.*)', admin.site.root),
)
其中
(r'^$', 'polls.helloworld.index'),
r’^$’ 是为了匹配空串 ,就是http://localhost:8000/
r’^$’, ‘polls.helloworld.index’),就是说 http://localhost:8000/ 这个地址将会指向
polls 这个工程里 helloworld.py 文件里定义的index方法,看看helloworld.py里面是不是有个def index(request):
举个例子,如果以后要想让http://localhost:8000/ blog 能被访问,只需要加个
r’^blog’ ,然后在后面写views来控制结果(这个以后会讲),够方便吧!
如果此时 web server已经启动,直接刷新页面就可以看到 hello world 了
很方便,django的url配置helloworld就是这样
相关文档:
我一直在用ultraedit看zope3的源代码.语法高亮设置可参考www.ultraedit.com
UltraEdit是一个很好的工具,但是默认不支持Python的语法高亮,下面是一个现成的WordFile片断,把这段文字Copy到UltraEdit下面的WORDFIL E.TXT文件中,保存后就可以看到UltraEdit对Python文件和语法的支持了^_^(注意,把/L11改为你的Wordfile的 ......
在 python的lib目录里有一个:this.py,它其实是隐藏着一首诗,源码如下:
s =
"""Gur Mra bs Clguba, ol Gvz Crgref
Ornhgvshy vf orggre guna htyl.
Rkcyvpvg vf orggre guna vzcyvpvg.
Fvzcyr vf orggre guna pbzcyrk.
Pbzcyrk vf ......
Python的ASCII, GB2312, Unicode , UTF-8
ASCII 是一种字符集,包括大小写的英文字母、数字、控制字符等,它用一个字节表示,范围是 0-127 Unicode分为UTF-8和UTF-16。
UTF-8变长度的,最多 6 个字节,小于 127 的字符用一个字节表示,与 ASCII 字符集的结果一样,ASCII 编码下的英语文本不需要修改就可以当作 UTF-8 编码 ......
模板是简单的文本文件,它可以是html格式或是xml,csv等格式的
模板包括变量,括它会被值所替代当运行时,以及标签它控制模板的逻辑运算如if,else等
下面是一个简单的模板,我们将会对它做详细的说明
{% extends "base_generic.html" %}
{% block title %}{{ section.title }}{% endblock %}
{% block content %}
< ......