标签:
参考:https://docs.djangoproject.com/en/1.9/intro/tutorial01/
1.进到想要的目录,
$ sudo django-admin startproject ProjectName
2.启动服务器
进入到manage.py的目录下
$ sudo python manage.py runserver 0.0.0.0:8000
3.创建应用
1)创建
进入manage.py 目录下
$ sudo python manage.py startapp polls
polls是app的文件名
2)修改view
进入polls
$ sudo vi views.py
添加
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You‘re at the polls index.")
3) 创建url
在polls文件下创建urls.py
polls/urls.py
$ sudo vi urls.py
添加
from django.conf.urls import url
from . import views
urlpatterns = [ url(r‘^$‘,views.index,name=‘index‘), ]
4)指向url
打开mysite/mysite/urls.py (注意,这里是子文件夹mysite,url.py已经存在)
添加
from django.conf.urls import url,include
from django.contrib import admin
urlpatterns = [ url(r‘^polls/‘, include(‘polls.urls‘)), url(‘^admin/‘,admin.site.urls), ]
(正则表达式: http://www.ziqiangxuetang.com/regexp/regexp-syntax.html)
5)
sudo python manage.py runserver
在网址/polls就可以打开了
标签:
原文地址:http://www.cnblogs.com/fuxiaotong/p/5124531.html