Django: UserAuthentication | ModuleNotFoundError: No module named 'userAuthentication' - django

I've been trying to create a user login and logout with django's bulid-in authenticated views.
I changed the project-level URL pattern
urlpatterns = [
path('admin/', admin.site.urls),
path('accounts/',include('django.contrib.auth.urls')),
path('', include('home.urls')),
]
added template registration/login.html
and updated LOGIN_REDIRECT_URL in settings.py
but still getting ModuleNotFoundError: No module named 'userAuthentication'.I don't know if I am missing anything in these it would be appreciated if anyone can give the heads up.
note: I was trying to recreate exactly this
https://docs.djangoproject.com/en/4.0/topics/auth/default/#module-django.contrib.auth.views
Installed Apps and middleware in settings.py

Related

Page not found at/admin

I'm a very beginner.
When I tried to go visit this (http://127.0.0.1:8000/admin), I couldn't. Here have shown page not found. What can be the solution?
Problem that I faced:
Page not found (404)
“D:\1_WebDevelopment\Business_Website\admin” does not exist
Request Method: GET
Request URL: http://127.0.0.1:8000/admin
Raised by: django.views.static.serve
Using the URLconf defined in business_website.urls, Django tried these URL patterns, in this order:
admin/
admin/
[name='index']
singup [name='handle_singUp']
login [name='handle_login']
logout [name='handle_logout']
contact [name='handle_contact']
frontend_orders [name='frontend_orders']
hire_me [name='hire_me']
^(?P<path>.*)$
The current path, admin, matched the last one.
You’re seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
Problem : open the picture
business_website urls.py:
from django.contrib import admin
from django.urls import path,include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('business_app.urls')),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
business_website url.py : open the picture
business_app urls.py:
from os import name
from django.contrib import admin
from django.urls import path
from .import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.index, name="index"),
path('singup', views.handle_singUp, name= "handle_singUp"),
path('login', views.handle_login, name="handle_login"),
path('logout', views.handle_logout, name="handle_logout"),
path('contact', views.handle_contact, name="handle_contact"),
path('frontend_orders', views.frontend_orders, name="frontend_orders"),
path('hire_me', views.hire_me, name="hire_me")
]
business_app url.py : open the picture
Delete from business_app urls.py this row:
path('admin/', admin.site.urls),
You should not call it twice.
You should set MEDIA_URL in settings to something. Like:
MEDIA_URL = '/media/'
Django urls need to have a trailing slash and the url you tried to access does not have it, check in your settings.py file if APPEND_SLASH is set to false
Among Django's many built-in features is APPEND_SLASH, which by default is set to True and automatically appends a slash / to URLs that would otherwise 404.
You can turn off this option by just setting APPEND_SLASH = False
You can read more here about why django uses trailing slashes
You have the same admin path defined in your root urls.py and in your app. It should probably be in just the root. Remove it from:
from os import name
from django.contrib import admin
from django.urls import path
from .import views
urlpatterns = [
# path('admin/', admin.site.urls), ##### REMOVE
path('', views.index, name="index"),
path('singup', views.handle_singUp, name= "handle_singUp"),
path('login', views.handle_login, name="handle_login"),
path('logout', views.handle_logout, name="handle_logout"),
path('contact', views.handle_contact, name="handle_contact"),
path('frontend_orders', views.frontend_orders, name="frontend_orders"),
path('hire_me', views.hire_me, name="hire_me")
]
Edit
After trying, and failing to reproduce the OP's error on my machine using all the answers given as of this writing, it turned out my original answer was not correct (not incorrect, but also not the solution), in fact the original answer given by Jaime Ortiz, was most likely the correct one.
But why was it so hard to come to this realization? Within the link he provided was this, which is why, when I initially tried his solution it did not work. Below is from the answer provided by
All Іѕ Vаиітy in that link. Note that within the [] is my insertion.
Since django observes both the urls [the one with the trailing slash
and the one without] as different, if you are caching your app, Django
will keep two copies for same page at ...
So either use admin/ instead of admin, or apply APPEND_SLASH = False to your settings.py, clear your browser cache and then you can use either, Django will append the slash automatically.

ModuleNotFoundError: No module named 'myapp.url'

I was creating my django first app. I added this code
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('myapp.url'))
]
from my project urls.py file to get my html code from my app url.py, but i keep getting this error when i want to run my server.
ModuleNotFoundError: No module named 'myapp.url'

Problem Extending Django-Oscar's layout.html

The problem appeared after I added a template to a minimal webapp. The template extends django-oscar's layout.html. Nothing else in the project extends layout.html.
My goal is simply to be able to use django-oscar templates to form the basis of web pages in my webapp. For some reason I am having no end of issues. This is only the latest error message. I have been struggling with this for days! When I resolve one issue, another shows up.
I made a minimal git repo for this problem: https://github.com/mslinn/django_oscar_problem
The repo has a requirements.txt file in case anyone wants to install the PIP modules necessary run the program.
I tried to ensure that I had the simplest possible project that shows the problem. In README.md I show the complete error message displayed in the web browser.
# /templates/welcome.html
{% extends 'oscar/layout.html' %}
... etc ...
# main/urls.py
from django.urls import include, path
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, 'home'),
path('admin/', admin.site.urls, 'admin'),
path('hello/', views.hello, 'hello'),
path('', include(apps.get_app_config('oscar').urls[0])),
]
# main/views.py
from django.shortcuts import render
def home(request):
return render(request, "welcome.html", {})
I then ran the webapp with:
$ ./manage.py runserver
The error message in the web browser after visiting http://localhost:8000 is:
ValueError at /
dictionary update sequence element #0 has length 1; 2 is required
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 3.1.6
Exception Type: ValueError
Exception Value:
dictionary update sequence element #0 has length 1; 2 is required
The problem is here:
urlpatterns = [
path('', views.home, 'home'),
path('admin/', admin.site.urls, 'admin'),
path('hello/', views.hello, 'hello'),
path('', include(apps.get_app_config('oscar').urls[0])),
]
The arguments you're passing to path() are not quite right. The signature for path is:
path(route, view, kwargs=None, name=None)
i.e., the third positional argument is expected to be kwargs passed to the view function - but you've passed a string instead, which is what causes the somewhat obscure error. I think you intend this to be the name, in which case you need to supply that as a named argument, i.e.,:
urlpatterns = [
path('', views.home, name='home'),
path('admin/', admin.site.urls, name='admin'),
path('hello/', views.hello, name='hello'),
path('', include(apps.get_app_config('oscar').urls[0])),
]
Note that this then results in a new TemplateDoesNotExist error in your sample repo - this is because the location of the templates directory is not somewhere that Django knows to look. You can fix this by adding the path to that directory to the DIRS configuration in your template settings, which is currently set to [].

How to fix the error for django 'django.core.exceptions.ImproperlyConfigured' with urls?

from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('polls/', include('polls.urls')),
]
There is an error when i add url to url.py.
when i run the code in terminal : 'python manage.py runserver' ; then the follwing error is displayed in the terminal -
django.core.exceptions.ImproperlyConfigured: The included URLconf
'<module 'polls.urls' from
'C:\\Users\\Administrator\\PycharmProjects\\website2\\mysite\\polls\\urls.py'>' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.
I searched everywhere for the solution but i couldn't find it. Please help me to get out of it.
I think this error most of u misunderstand, circular error imports are very rare in django only in flask it is frequent .
This error is caused by mispelling 'urlpatterns' in the urls.py which has been created in a django app.
Also it can be caused by not defining it in your urlpatterns in the urls.py file
Probably the error is caused by one of the above.
Its that easy
make sure in your polls app, you have a file called urls.py, which should look something like this:
from django.urls import path
from . import views
urlpatterns = [
path('', views.your_view),
]
If you haven't configured the views.py page in your polls app, then you can leave urlpatterns blank for now and you shouldn't see any errors.
This error might be coming because of the adimn in urls.py
urlpatterns = [
path('admin/', admin.site.urls),
path('polls/', include('polls.urls')),
]
When the polls path was removed by me, the website was running properly. So try comment the polls path in urls
urlpatterns = [
path('admin/', admin.site.urls),
#path('polls/', include('polls.urls')),
]

Django URLs management

I'm a full beginner on Django. Therefore, I'm sorry if my question is not making so much sense.
I'm studying Django tutorial - step 1. I installed properly Django and created my first Django project named 'vanilla'. The urls.py script of the vanilla project is
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
]
When I start Django with this 'vanilla' project and start the development server at http://127.0.0.1:8000/, I correctly see the start page (with a rocket).
In a second project that I named 'djtutorial', I created as requested in Django tutorial - step 1 a 'polls' app. As requested, I modified urls.py file in djtutorial\polls which now has following content:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
]
If I start the server the url http://127.0.0.1:8000/polls/ is working properly. However, if I launch the root url of the site (i.e. http://127.0.0.1:8000/), I now have a 404 error.
Why is the 'root url' of the site now hidden?
There wasn't any root URL at all. Main page informing you that your project is created properly shows up only if you don't have any view of your own added to urlpatterns. When you create any page, this welcome page stops showing up and that is expected.
If you want to show your own page on root of your website, use this in your urlpatterns:
path('', >>VIEW OR INCLUDE HERE<<),