简体   繁体   English

正确的django 1.11的URL模式

[英]Correct URL pattern for django 1.11

I'm currently running django version 1.11 and I want to create a blog. 我目前正在运行django 1.11版,我想创建一个博客。 I am at the process where I create a function based view to display html content. 我正处于创建基于函数的视图以显示html内容的过程中。 I keep running into this error. 我一直遇到这个错误。

File "/Users/Fanonx/Desktop/xventureblog/src/xventureblog/urls.py", line 21, in <module>
url(r'^admin/', include(admin.site.urls)),
NameError: name 'include' is not defined

Here is my code for views.py 这是我的views.py代码

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.http import HttpResponse
from django.shortcuts import render

# Create your views here.


def post_home(request):
    return HttpResponse("<h1>Hello<h1>")

here is my code for urls.py 这是我的urls.py代码

from django.conf.urls import url
from django.contrib import admin
from posts.views import post_home

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^posts/$', post_home),
]

You didn't import include from django.conf.urls , hence the exception you received (it's quite self-explanatory if you break it down). 你没有从django.conf.urls导入include,因此你收到了异常(如果你将其分解,这是非常明显的)。 Your urls.py first line should be: 你的urls.py第一行应该是:

from django.conf.urls import url, include

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM