I try to learn Django (1.10.1) and use the recording from the webinar, but got stuck at a moment where I can’t connect a view:
There are 2 folders in the project: MyBlog and blog . MyBlog\urls.py contains:
from django.conf.urls import url, include from django.contrib import admin urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^', include('blog.urls')) ] blog\urls.py contains:
from django.conf.urls import url, include from django.contrib import admin from . import views urlpatterns = ('', url(r'^$', blog.views.home, name='home'), ) blog\views.py contains:
from django.http import HttpResponse from django.shortcuts import render def home(request): return HttpResponse('Hello, World!') I'm confused, help. I understand that there is an error in the blog\urls.py in the line:
urlpatterns = ('', url(r'^$', blog.views.home, name='home'), ) When you run the code issues:
... File "G:\Proktor\Projects\MyBlog\blog\urls.py", line 23, in <module> url(r'^$', blog.views.home, name='home'), NameError: name 'blog' is not defined
views.home,views.home? - Flowneeeurlpatterns = (url(r'^$', views.home, name='home'), )- Mr. Fixblog.views.homewithviews.homeyouviews.homethe error:File "C:\Python27\lib\site-packages\django\core\management\base.py", line 420, in check raise SystemCheckError(msg) django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:ERRORS: ?: (urls.E004) Your URL pattern '' is invalid. Ensure that urlpatterns is a list of url() instances. HINT: Try removing the string ''. The list of urlpatterns should not have a prefix string as the first element. System check identified 1 issue (0 silenced).File "C:\Python27\lib\site-packages\django\core\management\base.py", line 420, in check raise SystemCheckError(msg) django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:ERRORS: ?: (urls.E004) Your URL pattern '' is invalid. Ensure that urlpatterns is a list of url() instances. HINT: Try removing the string ''. The list of urlpatterns should not have a prefix string as the first element. System check identified 1 issue (0 silenced).- EmptyMan