Import Error : cannot import register - django

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

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.

cannot import name 're_path' I am using django version 2.0.6

I want to use re_path from django.urls, django doc says I can use this from django version 2,
From the error I came to know that I am using django version 2.0.6.
But I am not able to re_path
ImportError at /
cannot import name 're_path'
Request Method: GET Request URL: http://djangosite.com/ Django Version:
2.0.6 Exception Type: ImportError Exception Value:
cannot import name 're_path'
Exception Location: /home/sugushiva/myproject/filope/blogs/urls.py in
, line 1 Python Executable: /usr/bin/python3
In main urls.py
from django.contrib import admin
from django.urls import path, re_path,include
urlpatterns= [
path('admin/',admin.site.urls),
re_path('^$', include('blogs.urls'))
]
in blogs.urls
from django.db import re_path
from .models import blogindex
urlpatterns = [
re_path('^$',blogindex)
]
You are importing the wrong path in blogs/urls.py.
from django.db import re_path
Should instead be:
from django.urls import re_path

ImportError: cannot import name 'classproperty'

What is the solution of this error........
from django.utils.decorators import classproperty
ImportError: cannot import name 'classproperty'
Why this error shows. How can I solve this problem ?
If you have this issue after 21 Oct 2019 that is because in this PullRequest classproperty were moved from django.utils.decorators to django.utils.functional.
You need to change your import statement or add some code to check what version of django are you using and from where to import the classproperty
try:
# Django 3.1 and above
from django.utils.functional import classproperty
except ImportError:
from django.utils.decorators import classproperty
Check your django version. This module is not there before django 1.9

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 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?