A
A
ahmed_al_asad2016-09-27 04:22:15
Django
ahmed_al_asad, 2016-09-27 04:22:15

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)
]

views.py file:
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.


def test(request):
    return HttpResponse("<h1>Simple text</h1>")

cd2f293dc7d64cfb8ebf8bdd18edc439.png
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hello kokos, 2016-09-27
@hello kokos

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 question

Ask a Question

731 491 924 answers to any question