python下的web开发框架-Django,url配置
2010-02-07 12:04
926 查看
url配置
我们在polls这个app下创建一个
helloworld.py
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, Django.")
修改 urls.py
其中
(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就是这样
我们在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就是这样
相关文章推荐
- Python web框架Django学习(1)——在win7 64bit下配置开发环境Django:一个可以使Web开发工作愉快并且高效的Web开发框架。 使用Django,使你能够以最小的代价构建和
- pythonWeb -- Django开发-视图层开发和URL配置
- PythonWeb开发Django框架学习(七)URL的配置
- Python Web 开发 学习笔记1 安装配置 python+django
- django--python之web开发框架搭建
- python下的web开发框架-Django,建立模型
- Python Web接口开发学习笔记(基于Django框架)(一)
- Python Web 框架,第 1 部分: 使用 Django 和 Python 开发 Web 站点
- 新手开发基于Django框架的python web(二)
- python开发学习-day15(前端部分知识、web框架、Django创建项目)
- 使用url_helper简化Python中Django框架的url配置教程
- Python中Django框架开发web
- Python Web 框架,第 1 部分: 使用 Django 和 Python 开发 Web 站点
- python下的web开发框架-Django,创建项目
- PythonWeb 开发Django框架(一) 4000 环境搭建
- python Web开发框架-Django (1)
- Python Web 框架,第 1 部分: 使用 Django 和 Python 开发 Web 站点
- Python的Django框架中的URL配置与松耦合
- python的web开发框架django学习笔记
- Python Web框架Django框架安装配置