Answer the question
In order to leave comments, you need to log in
Why doesn't Django want to import views?
I'm trying to import the function as written in the documentation but nothing comes out.
blog/urls.py file:
from django.conf.urls import url
from django.contrib import admin
from . import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^index/', views.test)
]
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def test(request):
return HttpResponse("<h1>Simple text</h1>")
Answer the question
In order to leave comments, you need to log in
Hello.
When you write:
from . import views - you are importing from the current directory.
In your case, it's "blog". You don't have it there: views.py
You need it like this:
from ..simple_blog imort views
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question