1.定义视图
打开booktest/views.py文件,定义视图index如下
from django.http import HttpResponse
def index(request):
return HttpResponse("index")
2.配置URLconf
在booktest/应用下创建urls.py文件,定义代码如下:
from django.conf.urls import url
from booktest import views
urlpatterns = [
url(r'^$', views.index),
]
3.
test1/urls.py文件完整代码如下:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('booktest.urls')),
]
4.重点来了: 39.106.27.236 是公网的ip
打开settings.py
DEBUG = True
ALLOWED_HOSTS = ['39.106.27.236','0.0.0.0:8000','localhost']
或写 ALLOWED_HOSTS = ['*'] 也是可以的
5.重启:注意是用 0.0.0.0:8000
python manage.py runserver 0.0.0.0:8000
6.得到视图前端效果
网友评论