1

Ive setup django and am setting up my urls like

from django.conf.urls import include, url
from django.contrib import admin
 from . import views

urlpatterns = [
   url(r'^admin/', include(admin.site.urls)),
   url(r'^home/$', views.homepage),
]

The above always produces an error

cannot import name views

PROJECT STRUCTURE

geoff
   settings.py
   urls.py  //using this
   wsgi.py

 homepage
   migrations->folder
   _init_.py
   .....others here
   views.py
11
  • show your project structure for better understanding Commented Nov 3, 2017 at 5:32
  • this is main URL file... in main project folder. || Go to app folder and create urls.py and import the same. || from . import something means you should have the something file in the same directory. Commented Nov 3, 2017 at 5:34
  • use this from __future__ import absolute_import hope this solved your issue Commented Nov 3, 2017 at 5:37
  • @Kalariya_M ive updated the question with project structure Commented Nov 3, 2017 at 5:40
  • 1
    You have a homepage directory where views.py is located, in which case you need to do from homepage import views. Commented Nov 3, 2017 at 5:45

3 Answers 3

3

Try:

from homepage import views
Sign up to request clarification or add additional context in comments.

2 Comments

@GEOFFREYMWANGI you include it the same way
@GEOFFREYMWANGI if you have differents views.py you can use different import name like example from homepage import views as views1
0

You need to change from . import views to from homepage.views import homepage(mapping function)

Comments

0

You have a indent issue in your urls.py.

Check the below line

`from . import views`

You have a extra space at start of this line. Please remove the space your problem will gets solved.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.