from django.urls import ( # noqa ModuleNotFoundError: No module named 'django.urls' [duplicate] - django

I'm using django==1.8, rest_framework=3.7.7, python==2.7.12
urls.py
urlpatterns += [
url(r'^api/core/', include('core.urls')),
]
core/urls.py
urlpatterns=[
url(r'^/users/', core_view.userlist),
]
views.py
class UserList(generics.ListAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
userlist = UserList.as_view()
When I'm navagating to: http://localhost:8000/api/core/users I'm getting the following error:
ImportError at /api/core/users
No module named urls
Request Method: GET
Request URL: http://localhost:8000/api/core/users
Django Version: 1.8
Exception Type: ImportError
Exception Value:
No module named urls
Exception Location: /usr/local/lib/python2.7/dist-packages/rest_framework/compat.py in <module>, line 26
Python Executable: /usr/bin/python
Python Version: 2.7.12
what is wrong in configuration?

Django Rest Framework dropped support for Django 1.8 in version 3.7.
You should install an earlier version of rest framework, or upgrade Django (note that Django 1.8 reaches end-of-life in April 2018)

Just Make sure you include core app in your INSTALLED_APPS settings, and that you have init.py in your core directory folder.
Look here for more information.

Related

No module names urls

Error: Importerror
Python version: 2.7
Django version: 1.8.4
Whenever i start my localhost server, i get this error, the error is pointing towards from
django.urls import re_path in grapelli/urls.py, code provided in the end.
***
**ImportError at /
No module named urls
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.8.4
Exception Type: ImportError
Exception Value:
No module named urls
Exception Location: /mnt/c/users/verma/desktop/opine/env/local/lib/python2.7/site-
packages/grappelli/urls.py in <module>, line 3
Python Executable: /mnt/c/users/verma/desktop/opine/env/bin/python
Python Version: 2.7.17
Python Path:
['/mnt/c/users/verma/desktop/opine',
'/mnt/c/users/verma/desktop/opine/env/lib/python2.7',
'/mnt/c/users/verma/desktop/opine/env/lib/python2.7/plat-x86_64-linux-gnu',
'/mnt/c/users/verma/desktop/opine/env/lib/python2.7/lib-tk',
'/mnt/c/users/verma/desktop/opine/env/lib/python2.7/lib-old',
'/mnt/c/users/verma/desktop/opine/env/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/mnt/c/users/verma/desktop/opine/env/local/lib/python2.7/site-packages',
'/mnt/c/users/verma/desktop/opine/env/lib/python2.7/site-packages']***
Server time: Wed, 6 Jan 2021 03:07:09 +0530**
/mnt/c/users/verma/desktop/opine/env/local/lib/python2.7/site-packages/grappelli/urls.py in
grappelli/urls.py : I have used grappelli in my project for admin access.
**
# coding: utf-8
from django.urls import re_path
from .views.related import AutocompleteLookup, M2MLookup, RelatedLookup
from .views.switch import switch_user
urlpatterns = [
# FOREIGNKEY & GENERIC LOOKUP
re_path(r'^lookup/related/$', RelatedLookup.as_view(), name="grp_related_lookup"),
re_path(r'^lookup/m2m/$', M2MLookup.as_view(), name="grp_m2m_lookup"),
re_path(r'^lookup/autocomplete/$', AutocompleteLookup.as_view(), name="grp_autocomplete_lookup"),
# SWITCH USER
re_path(r'^switch/user/(?P<object_id>\d+)/$', switch_user, name="grp_switch_user"),
]
**
Error in line no. 1: from django.urls import re_path
How do I fix this, because URLs is not another module created by me, it's an inbuilt one in Django.

django_select2 Caught NameError while rendering: name 'patterns' is not defined

I am using django_select2 with my mezzanine project.
As per doc i follow processes.
#step1 :
pip install django-select2
#Step2 :
url(r'^select2/', include('django_select2.urls')),
But when i reloaded my website i got error
TemplateSyntaxError at /admin/cms_shop/deliverymethod/200/
Caught NameError while rendering: name 'patterns' is not defined
Request Method: GET
Request URL: https://example.net/admin/cms_shop/deliverymethod/200/
Django Version: 1.3.1
Exception Type: TemplateSyntaxError
Exception Value:
Caught NameError while rendering: name 'patterns' is not defined
Exception Location: /home/django/cmsenv/lib/python2.6/site-packages/django_select2/urls.py in , line 5
Python Executable: /home/django/cmsenv/bin/python
Python Version: 2.6.5
Python Path:
['/home/django/core/python/cmsintegration',
'/home/django/cmsenv/lib/python2.6/site-packages/distribute-0.6.14-py2.6.egg',
'/home/django/cmsenv/lib/python2.6/site-packages/pip-0.8.3-py2.6.egg',
'/home/django/cmsenv/lib/python2.6/site-packages/paython-0.0.1-py2.6.egg',
'/home/django/cmsenv/lib/python2.6/site-packages/django_shop-0.0.11.dev0-py2.6.egg',
'/home/django/cmsenv/lib/python2.6/site-packages/django_recaptcha-0.0.6-py2.6.egg',
'/home/django/cmsenv/lib/python2.6',
'/home/django/cmsenv/lib/python2.6/plat-linux2',
'/home/django/cmsenv/lib/python2.6/lib-tk',
'/home/django/cmsenv/lib/python2.6/lib-old',
'/home/django/cmsenv/lib/python2.6/lib-dynload',
'/usr/lib/python2.6',
'/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk',
'/home/django/cmsenv/lib/python2.6/site-packages',
'/home/django/cmsenv/lib/python2.6/site-packages/PIL']
Please help me what i am doing wrong.
my urls.py code is
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns("",
url(r'^admin/cms_shop/productimport/delete_selected/([\w]+)/$', delete_selected_import_view, name="cms_shop_delete_selected_import"),
url("^admin/", include(admin.site.urls)),
url(r'^select2/', include('django_select2.urls')),
)
in settting.py
INSTALLED_APPS = (
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.redirects",
"django.contrib.sessions",
"django.contrib.sites",
"django.contrib.sitemaps",
"mezzanine.conf",
"mezzanine.core",
"mezzanine.blog",
"mezzanine.pages",
"mezzanine.generic",
"userapp",
"django_select2",
)
FYI, you have Django 1.3 and should consider upgrading to 1.5.
Have you tried
from django.conf.urls import patterns
You'll get this error if you are upgrading to Django 1.8 or above.
Here is the new way to do it without patterns:
https://docs.djangoproject.com/ja/1.9/releases/1.8/#s-django-conf-urls-patterns
urlpatterns = [
url('^$', views.myview),
url('^other/$', views.otherview),
]

cannot import name admin

I am new at Django. I am trying to create basic admin panel. when I changed the urls.py file and I put url(r'^admin/', include(admin.site.urls)), into patterns then it gave error like that:
Request Method: GET return
Request URL: http://127.0.0.1:8000/
Django Version: 1.4
Exception Type: ImportError
Exception Value:cannot import name admin
Exception Location:/home/ulascan/Desktop/projects/purple/purple/urls.py in <module>, line 1
Python Executable: /usr/bin/python
Python Version: 2.7.3
Python Path:
['/home/ulascan/Desktop/projects/purple',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2'
...
...]
Make sure that in your settings.py you have django.contrib.admin, uncommented in INSTALLED_APPS. And also check that you have these lines in your urls.py:
from django.contrib import admin
admin.autodiscover()

django templatedoesnotexist current_date

I'm going through the Django Book. I'm in the middle of Chapter 4. I can't render my current_datetime.html template view. What am I doing wrong? It looks like the template loaders are not finding the right directory. http://www.djangobook.com/en/2.0/chapter04/
I have created my templates directory in my project folder and current_datetime.html with in the directory.
Setting.py
import os.path
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), 'templates').replace('\\','/'),
# I've also tried: # '/Users/macuser/Python_Projects/django_test1/templates',
)
views.py
from django.shortcuts import render_to_response
import datetime
def current_datetime(request):
now = datetime.datetime.now()
return render_to_response('current_datetime.html', {'current_date': now})
urls.py
from django.conf.urls import patterns, include, url
from django_test1.views import hello, my_homepage_view, current_datetime, hours_ahead
urlpatterns = patterns('',
(r'^$', my_homepage_view),
(r'^hello/$', hello),
(r'^time/$', current_datetime),
(r'^time/plus/(\d{1,2})/$', hours_ahead),)
The error:
TemplateDoesNotExist at /time/
current_datetime.html
Request Method: GET
Request URL:
Django Version: 1.4
Exception Type: TemplateDoesNotExist
Exception Value:
current_datetime.html
Exception Location: /Library/Python/2.7/site-packages/django/template/loader.py in find_template, line 138
Python Executable: /usr/bin/python
Python Version: 2.7.1
Python Path:
['/Users/macuser/Python_Projects/django_test1',
'/Library/Python/2.7/site-packages/distribute-0.6.27-py2.7.egg',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
'/Library/Python/2.7/site-packages']
Server time: Mon, 23 Jul 2012 20:40:35 -0500
Template-loader postmortem
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
/Library/Python/2.7/site-packages/django/contrib/auth/templates/current_datetime.html (File does not exist)
You havn't checked render_to_Response format
https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#render-to-response
Go through it, You need to add context_instance=RequestContext(request) to the response
This was a silly mistake. I did not create an actual app: python manage.py startapp "appName". I put "assert False" in the settings file and realized django was not even using my settings.py file.

DJANGO RESTAPI--No module found error

I downloaded the code from the following link and stored it in the location below,
http://django-rest-interface.googlecode.com/svn/trunk/ django-rest-interface
Location
c:/Python27/Djangoprojects/django_restapi
Project Location
c:/Python27/Djangoprojects/mysite/polls
URLS.py
from django.conf.urls.defaults import *
from polls.views import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^polls/$',index),
(r'^polls/(?P<poll_id>\d+)/$',detail),
(r'^polls/(?P<poll_id>\d+)/results/$',results),
(r'^polls/(?P<poll_id>\d+)/vote/$',vote),
(r'^admin/', include(admin.site.urls)),
(r'^xml/polls/(.*?)/?$',xml_poll_resource),
)
views.py
from django_restapi.model_resource import Collection
from django_restapi.responder import XMLResponder
from django_restapi.responder import *
from django_restapi_tests.polls.models import Poll, Choice
xml_poll_resource = Collection(
queryset = Poll.objects.all(),
permitted_methods = ('GET', 'POST', 'PUT', 'DELETE'),
responder = XMLResponder(paginate_by = 10)
)
I get the following error when I try the URL specified below,
Error:
ImportError at /xml/polls/
No module named django_restapi.model_resource
Request Method:
GET
Request URL:
http://127.0.0.1:8000/xml/polls/
Django Version:
1.3.1
Exception Type:
ImportError
Exception Value:
No module named django_restapi.model_resource
Exception Location:
C:\Python27\Djangoprojects\mysite..\mysite\polls\views.py in , line 1
Python Executable:
C:\Python27\python.exe
Python Version:
2.7.2
Python Path:
['C:\Python27\Djangoprojects\mysite',
'C:\Python27\lib\site-packages\setuptools-0.6c11-py2.7.egg',
'C:\Python27\lib\site-packages\django_db_log-2.2.1-py2.7.egg',
'C:\Python27',
'c:\Python27\lib\site-packages\django\bin\django-admin.py',
'c:\mysql',
'c:\pythonpath\djangoprojects\django_restapi',
'C:\Windows\system32\python27.zip',
'C:\Python27\DLLs',
'C:\Python27\lib',
'C:\Python27\lib\plat-win',
'C:\Python27\lib\lib-tk',
'C:\Python27\lib\site-packages',
'C:\Python27\lib\site-packages\wx-2.8-msw-unicode']
Server time:
Thu, 12 Jul 2012 22:31:04 -0400
How do I resolver this error?
As from your code, Polls directory should be inside django_restapi and you should put parent of django_restapi in python path.
Did you check the setting.py file?