Issue
I'm a total beginer at Django. Please help me to solve it, I've been trying to do so for 2 days. Essentially I created a model, defined a class there but when I open the page I get the error
Using the URLconf defined in reports_proj.urls, Django tried these URL patterns, in this order:
admin/
^static/(?P<path>.*)$
^media/(?P<path>.*)$
The empty path didn’t match any of these.
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),
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
admin.py
from django.contrib import admin
from .models import Profile
admin.site.register(Profile)
settigs.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
#our apps
'customers',
'products',
'profiles',
'reports',
'sales',
#3rd party
'crispy_forms'
]
When I put path('login/', admin.site.urls),
it works but shows me Please enter the correct username and password for a staff account.
whenever I try to log in as admin.
It seems like I should write some methods in views.py, because it has only from django.shortcuts import render
line. If it's true, which ones?
Solution
I will try to explain how django works in a simple way.
In urls.py you define which view (from views.py) will be shown, In views.py you link template(HTML) and pass data from database (models.py) to this HTML
So if you want to create for example car dealership website you would need to
- In Models.py create a model for a car,
- In templates/ create a HTML file with a front-end
- In views.py pass car model from models.py to template (HTML)
- In urls.py link views.py to a certain path
if users goes to www.domain.com/cars django will first look at urls.py to check if you defined "/cars" path -> from there check linked view.py to see which HTML show to a user
I would advise you to go though Django tutorial
https://docs.djangoproject.com/en/3.2/intro/tutorial01/
Answered By - bazzuk123
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.