在之前的项目中mysite下新建一个view.py内容如下:
from django.http import HttpResponse
def hello(request):
return HttpResponse("hello world !!!!")
在urls.py中内容如下:
from django.conf.urls.defaults import patterns, include, url
from mysite.view import hello
urlpatterns = patterns('',
('^hello/$',hello),
)
^hello/$ 为正则匹配的url串
hello为view.py中定义的方法名,参数必须包含request
启动server:
python manage.py runserver 8080
http://127.0.0.1:8080/hello/
访问可看到hello world !!!!页面
from django.http import HttpResponse
def hello(request):
return HttpResponse("hello world !!!!")
在urls.py中内容如下:
from django.conf.urls.defaults import patterns, include, url
from mysite.view import hello
urlpatterns = patterns('',
('^hello/$',hello),
)
^hello/$ 为正则匹配的url串
hello为view.py中定义的方法名,参数必须包含request
启动server:
python manage.py runserver 8080
http://127.0.0.1:8080/hello/
访问可看到hello world !!!!页面