简体   繁体   中英

Correct URL pattern for django 1.11

I'm currently running django version 1.11 and I want to create a blog. I am at the process where I create a function based view to display html content. 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

# -*- 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

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). Your urls.py first line should be:

from django.conf.urls import url, include

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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