美文网首页
centos7搭建django简单上线.3---视图实现-->开

centos7搭建django简单上线.3---视图实现-->开

作者: Kevin0is0me | 来源:发表于2019-05-25 21:33 被阅读0次

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.得到视图前端效果

相关文章

网友评论

      本文标题:centos7搭建django简单上线.3---视图实现-->开

      本文链接:https://www.haomeiwen.com/subject/oxnzzqtx.html