No module names urls - django

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.

Related

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

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.

Import Error : cannot import register

Getting Import error while trying to run localhost from my urls.py:
from django.conf.urls.defaults import *
from django.conf import settings
from django.http import HttpResponseRedirect
from django.contrib import admin
from mainapp.feeds import LatestReports, CityIdFeed, CitySlugFeed, WardIdFeed, WardSlugFeed,LatestUpdatesByReport
from mainapp.models import City
from social_auth.views import auth as social_auth
from social_auth.views import disconnect as social_disconnect
#Error at this line
from registration.views import register
from mainapp.forms import FMSNewRegistrationForm,FMSAuthenticationForm
from mainapp.views.account import SUPPORTED_SOCIAL_PROVIDERS
from django.contrib.auth import views as auth_views
from mainapp.views.mobile import open311v2
import mainapp.views.cities as cities
Traceback:
ImportError at /
cannot import name register
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.3
Exception Type: ImportError
Exception Value:
cannot import name register
Exception Location: /home/sourabh/Django/fixmystreet/fixmystreet/../fixmystreet/urls.py in <module>, line 9
Python Executable: /home/sourabh/Django/fixmystreet/bin/python
Python Version: 2.7.3
Python Path:
['/home/sourabh/Django/fixmystreet/fixmystreet',
'/home/sourabh/Django/fixmystreet/local/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg',
'/home/sourabh/Django/fixmystreet/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg',
'/home/sourabh/Django/fixmystreet/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg',
'/home/sourabh/Django/fixmystreet/lib/python2.7/site-packages/pip-1.1-py2.7.egg',
'/home/sourabh/Django/fixmystreet/lib/python2.7',
'/home/sourabh/Django/fixmystreet/lib/python2.7/plat-linux2',
'/home/sourabh/Django/fixmystreet/lib/python2.7/lib-tk',
'/home/sourabh/Django/fixmystreet/lib/python2.7/lib-old',
'/home/sourabh/Django/fixmystreet/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/home/sourabh/Django/fixmystreet/local/lib/python2.7/site-packages',
'/home/sourabh/Django/fixmystreet/local/lib/python2.7/site-packages/PIL',
'/home/sourabh/Django/fixmystreet/lib/python2.7/site-packages',
'/home/sourabh/Django/fixmystreet/lib/python2.7/site-packages/PIL']
Server time: Thu, 22 Aug 2013 09:34:40 -0500
If you look at the docs you see that register is something that used to exist and was deprecated in the last version. From the documentation:
The 1.0 release of django-registration represents a complete rewrite
of the previous codebase, and introduces several new features which
[...]
You either downgrade to django-registration v0.8 (where registration.views.register still exists) or learn how to implement the changes to fit the newest version

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?