import error

300 views
Skip to first unread message

sarvit sarvit

unread,
Feb 5, 2018, 8:24:59 AM2/5/18
to Django users
Hello 
I importing error 
Please help me 
from django.shortcuts import render
from django.conf.urls import url
from django.contrib import admin
from django.urls import path
from . import views


Traceback (most recent call last):
  File "c:\Users\saeid\Desktop\sade\env\Post\Post\urls.py", line 20, in <module>
    from . import views
ImportError: cannot import name 'views'



pradam

unread,
Feb 5, 2018, 8:54:41 AM2/5/18
to django...@googlegroups.com
Bro, 
do it like this:
from your_app_name import views

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2ff76016-b9a4-47dc-a4c1-87a828e86c0f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

sarvit sarvit

unread,
Feb 5, 2018, 8:59:27 AM2/5/18
to Django users
is not app 
views.py
from django.http import HttpRequest

def index(request):
   return HttpRequest("Hello World.")

urls.py

from django.shortcuts import render
from django.conf.urls import url
from django.contrib import admin
from django.urls import path
from views.py import views

urlpatterns = [
   path('admin/', admin.site.urls),
   url(r'^$',views.index),


]

Matemática A3K

unread,
Feb 5, 2018, 9:06:57 AM2/5/18
to django...@googlegroups.com
On Mon, Feb 5, 2018 at 10:59 AM, sarvit sarvit <saeedesk...@gmail.com> wrote:
is not app 
views.py
from django.http import HttpRequest

def index(request):
   return HttpRequest("Hello World.")

urls.py

from django.shortcuts import render
from django.conf.urls import url
from django.contrib import admin
from django.urls import path
from views.py import views

urlpatterns = [
   path('admin/', admin.site.urls),
   url(r'^$',views.index),


]



Judging from this, you are trying to import the views from your "main" urls.py, and generally the views are within an django app. In that case, you should use your_app_name.views as stated before. "Relative imports" (from . import views) will work only if the file is on the same directory you are working (i.e. inside an app).
 .


On Monday, February 5, 2018 at 4:54:59 PM UTC+3:30, sarvit sarvit wrote:
Hello 
I importing error 
Please help me 
from django.shortcuts import render
from django.conf.urls import url
from django.contrib import admin
from django.urls import path
from . import views


Traceback (most recent call last):
  File "c:\Users\saeid\Desktop\sade\env\Post\Post\urls.py", line 20, in <module>
    from . import views
ImportError: cannot import name 'views'



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages