Aktualnie pracuję nad wersją 1.11 Django i chcę utworzyć bloga. Jestem w trakcie procesu tworzenia widoku opartego na funkcjach do wyświetlania treści html. Ciągle napotykam ten błąd.
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
Oto mój kod dla 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>")
tutaj jest mój kod dla 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),
]
Odpowiedzi:
2 dla odpowiedzi № 1Nie importujesz z tego adresu django.conf.urls
, stąd wyjątek, który otrzymałeś (to całkiem zrozumiałe, jeśli je zepsujesz) urls.py
pierwsza linia powinna być:
from django.conf.urls import url, include