No module named 'django.urls' when installing django-registration-redux - python

I'm trying to set up django-registration-redux, but when I set up the
url(r'^accounts/', include('registration.backends.default.urls')),
in the urls.py file and I try to access any page I get the following error message:
ModuleNotFoundError
No module named 'django.urls'
I have checked the manual several times and everything is in order. What is missing? Where is my mistake?
urls.py file
"""p110 URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.8/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf import settings
from django.conf.urls.static import static
from django.conf.urls import include, url
from django.contrib import admin
from boletin import views
from .views import about
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^$', views.index, name='index'),
url(r'^contact/$', views.contact, name='contact'),
url(r'^about/$', about, name='about'),
url(r'^accounts/', include('registration.backends.default.urls')),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)

The latest version of django-registration-redux requires Django 1.11+. If you are using an earlier version of Django, then you could use django-registration-redux 1.9, which supports Django 1.8+.
Note that you should really be upgrading to Django 1.11 or newer. Django 1.9 and 1.10 are no longer supported, and long term support for Django 1.8 ends in April 2018.

Related

The included URLconf does not appear to have any patterns in it. Error in Django

The included URLconf '<module 'myapp.urls' from 'C:\\Users\\Hp\\Desktop\\Python\\Django Projects\\myproject\\myapp\\urls.py'>' does not appear to have any patterns in it. If you see the 'urlpatterns' variable with valid patterns in the file then the issue is probably caused by a circular import.
This is the error that I am getting while building my django app.
Here is urls.py from myapp -
from django.urls import path
from . import views
urlpatterns=[
path('', views.index, name='index')
]
Here is views.py -
from django.shortcuts import render
from django import HttpResponse
# Create your views here.
def index(request):
return HttpResponse('<h1>Hey, Welcome</h1>')
this is from urls.py from myproject-
"""myproject URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('myapp.urls')),
]
try to edit your view file like the following :
from django.shortcuts import render
#this is new
from django.http import HttpResponse
# Create your views here.
def index(request):
return HttpResponse('<h1>Hey, Welcome</h1>')

Django 2.0.5 404 error-page not found

I am new in using Django and I am having some problems. When I run my server 'runserver' it shows 404 page not found. My project directory name is 'mysite' and my app name is 'webapp'. The problem I think is in 'urls' file. I have also put my app name in INSTALLED_APPS under the settings section.
This is the code in mysite/urls.py file:
"""mysite URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('webapp', include("webapp.urls")),
]
And this is the code in webapp/urls.py file:
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name = "index"),
]
I am using the latest Django version 2.0.5, I have tried to look up for this error but most of them seems to be of the older versions of Django.
I would appreciate any help, in this problem.
In your webapp/urls.py, you have to specify app name like
app_name = "webapp"
mysite/urls
urlpatterns =
[
path('webapp/'), include() )
]
Note: parent urls must contain trailing slash.
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('webapp/', include('webapp.urls')),
]
You forgot to add backslash after webapp in path "webapp/" which would help to redirect to further methods in views.
As nothing has been defined for your root URL,it is thus empty and the 404 error occurs.To solve it,simply type the path to your view after the local server URL in your address bar.i.e "127.0.0.1:8000/webapp" or use "localhost/name_of_url"

Issues with path() in urls.py in django 2.0.5

I am trying to do the following thing in urls.py but Django 2.0.5 doesn't seem to support url(). Instead of it, I used path() but still, its throwing invalid syntax error.
Can someone give a clearer picture of path() as it seems to be not supporting regex.
Providing the code here:
from django.contrib import admin
from django.urls import path
from .views import home_page
urlpatterns = [
path('$', home_page)
path('admin/', admin.site.urls),
]
You miss a ,, and $ is unnecessary
from django.contrib import admin
from django.urls import path
from .views import home_page
urlpatterns = [
path('', home_page),
path('admin/', admin.site.urls),
]
Django2 has 2 functions for URLconfs, path(), re_path().
You can use regex paths (regular expression based paths) with re_path(), so remove $ and place , between two consecutive paths.
Note: Let suppose your app name is my_django_app created by python manage.py startapp my_django_app command.
I created a new Django app named my_django_app and tried, it works fine. I have the following code in my urls.py file.
"""my_django_proj URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from my_django_app.views import home_page
urlpatterns = [
path('', home_page),
path('admin/', admin.site.urls),
]
References: https://docs.djangoproject.com/en/2.0/topics/http/urls/
django 2.0 - including urls file from an app to the root urls file
Thanks.
If you prefer to use url instead of path, that will work just fine. You just have to import from django.conf.urls instead. So your import statement should look like this:
from django.conf.urls import url
Django says on their documentation page that this feature will likely be deprecated in future versions to re-path, however, url still works fine for me, and I'm running Django 2.0.7... so, I imagine it would work with yours as well. I guess because of this, with Django version 2 and above, it nows decides when it creates the boilerplate project that instead of importing urls from django.conf.urls, it imports path from django.urls. (Note: PATH doesn't allow for regex)
What I typically do, is create an app specific urls.py. In that urls.py I'll import url from django.conf.urls and have my specific app level urls there:
from django.conf.urls import url
from app_name import views # have to import views
urlpatterns = [
url(r'^$', views.index),
url(r'^users$',views.users),
]
Then in the project level urls.py I'll add the include module as so I can link it to my app specific urls.py file:
from django.conf.urls import url, include
from django.contrib import admin
from app_name import views
urlpatterns = [
url(r'^',include('app_name.urls')),
url(r'^admin/', admin.site.urls),
]
(Note: If you have a separate folder in between such that the folder structure looks something like mainproject>apps>app_name>(settings.py, views.py, admin.py etc...) you will have to create an __init__.py file in the apps folder as so Django can recognize the module.
urlpatterns = [
path('', home_page),
path('admin/', admin.site.urls)
]
As stated in the above answers, the $ is unnecessary while using path(). You are getting a syntax error due to the comma after admin.site.urls) which should be removed.

(urls.W005) URL namespace 'LnkIn' isn't unique.

Hi I'm getting this error when doing my migrations or using the python manage.py runserver command.
(urls.W005) URL namespace 'LnkIn' isn't unique.You may not be able to reverse all URLs in this namespace.
This is how I have my urls.py inside my app directory (LnkIn).
from django.conf.urls import url
from . import views
app_name = 'LnkdIn'
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^register/$', views.register, name='register'),
url(r'^login_user/$', views.login_user, name='login_user'),
url(r'^logout_user/$', views.logout_user, name='logout_user'),
url(r'^(?P<user_id>[0-9]+)/$', views.profile, name='profile'),
url(r'^(?P<song_id>[0-9]+)/favorite/$', views.favorite, name='favorite'),
url(r'^trabajos/$', views.trabajos, name='trabajos'),
url(r'^crear_oferta/$', views.crear_oferta, name='crear_oferta'),
url(r'^(?P<user_id>[0-9]+)/create_trabajo/$', views.create_trabajo, name='create_trabajo'),
url(r'^(?P<user_id>[0-9]+)/crear_amistad/$', views.crear_amistad, name='crear_amistad'),
url(r'^(?P<user_id>[0-9]+)/delete_trabajo/(?P<trabajo_id>[0-9]+)/$', views.delete_trabajo, name='delete_trabajo'),
url(r'^(?P<album_id>[0-9]+)/favorite_album/$', views.favorite_album, name='favorite_album'),
url(r'^(?P<album_id>[0-9]+)/delete_album/$', views.delete_album, name='delete_album'),
]
And this is how I have my urls.py in my main directory.
from django.conf.urls import include, url
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^LnkdIn/', include('LnkdIn.urls')),
url(r'^', include('LnkdIn.urls')),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
I really have no idea what could I've done wrong. I checked in my views and in my templates and everything seems to be fine, I don't seem to be having any typo on my urls. I've search but haven't find this error, I've seem similars one and they suggest to check not having mistakes in the urls.
I'm using Python 2.7 and Django 1.10.
You are importing LnkdIn.urls twice to your application urlpatterns.
You should only do it once, so choose either one from the section below
url(r'^LnkdIn/', include('LnkdIn.urls')),
or
url(r'^', include('LnkdIn.urls')),

How Do I Properly Set Up URLConf in Django (RegEx?)

I've recently completed the Django Tutorial and am now working on my own web app. The problem I am having is setting up the URLConf for this application. I still don't fully understand the RegEx matching in order to link different pages to each other (or maybe I'm just forgetting something simple??)
I'm trying to setup the URLConf in a way such that when I click a button on each page, it will travel to the next page (there are 5 total).
Here is what it should look like
Page 0 (http://127.0.0.1:8000/)
Page 1 (http://127.0.0.1:8000/page1/)
And continue in this pattern (http://127.0.0.1:8000/page2/, http://127.0.0.1:8000/page3/, http://127.0.0.1:8000/page4/)
When I click Next Page on Page 0, it goes to Page 1. When I click Submit on Page 1, the URL slug page1 changes to page2 but still displays the same html page.
Here are my two urls.py files:
"""qfdjango URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.8/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Add an import: from blog import urls as blog_urls
2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls))
"""
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
# builds URLS for all across the site
# decoupled from mainsite.urls
urlpatterns = patterns('',
url(r'^', include('mainsite.urls')),
url(r'^someOtherPage/', include('mainsite.urls')),
url(r'^anotherPage/', include('mainsite.urls')),
url(r'^page1/', include('mainsite.urls')),
url(r'^page2/', include('mainsite.urls')),
url(r'^page3/', include('mainsite.urls')),
url(r'^page4/', include('mainsite.urls')),
url(r'^admin/', include(admin.site.urls)),
)
"""qfdjango URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.8/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Add an import: from blog import urls as blog_urls
2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls))
"""
from django.conf.urls import patterns, include, url
# these patterns are for specific sections of the site
# the 'primary' URLs are located in qfdjango.urls
# URL design of an app is specific to the app,
# not the whole Django project
urlpatterns = patterns('mainsite.views',
url(r'^$', 'index'),
url(r'$', 'page_1'),
url(r'$', 'page_2'),
url(r'$', 'page_3'),
url(r'$', 'page_4'),
)
It seems you have defined the urls in a wrong way.
It should be something like:
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^', include('mainsite.urls')), # include your app urls once
url(r'^admin/', include(admin.site.urls)),
)
Then in app's urls.py file, urls should be defined like:
from django.conf.urls import patterns, include, url
urlpatterns = patterns('mainsite.views',
url(r'^$', 'index'),
url(r'^someOtherPage/$', 'someOtherPage'),
url(r'^anotherPage/$', 'anotherPage'),
url(r'page1/$', 'page_1'), # page 1 url
url(r'page2/$', 'page_2'), # page 2 url
url(r'page3/$', 'page_3'), # page 3 url
url(r'page4/$', 'page_4'), # page 4 url
)

Categories