How to remove the unspecified space between root and include url in django 2.2 - django

I am trying to create a Django website. I have specified the path to one of my apps. But I am getting an unspecified space in the pattern.I am using Django 2.2. screenshot of the django debug page
my base urls.py file
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('', include('homepage.urls')),
path('account/', include('account.urls')),
path('admin/', admin.site.urls),
path('db/', include('dashboard.urls')),
]
my dashboard/urls.py file
from django.urls import include, path
from .import views
urlpatterns = [
#author dashboard
path('authordboard/<int:auth_id/',views.author_dboard, name='author_details'),
#reviewer dashboard
path('reviewdboard/<int:re_id/',views.re_dboard, name='reviewer_details'),
]
I have included the dashboard app in the settings.py file.
Please help! Thanks in advance!

you must close variable declared in url. in your dashboard/urls.py:
from django.urls import include, path
from .import views
urlpatterns = [
#author dashboard
path('authordboard/<int:auth_id>/',views.author_dboard, name='author_details'),
#reviewer dashboard
path('reviewdboard/<int:re_id>/',views.re_dboard, name='reviewer_details'),
]

Related

You are seeing this page because DEBUG=True is in your settings file and you have not configured any URLs

the explorer in vscode Getting the error: You are seeing this page because DEBUG=True is in your settings file and you have not configured any URLs.
meetups/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('meetups/', views.index) #domain_name.com/meetups/
]
urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('meetups.urls'))
]
views.py
from django.shortcuts import render
# Create your views here.
def index(request):
return render(request,'templates/meetups/index.html')
You probably didn't add your app (meetups) into settings.INSTALLED_APPS, which can be found in your_project_name/settings.py.
Change meetups/templates/index.html to meetups/index.html also add name in your urlpatterns

Base "/" not found in Django

My django project ornaments has only one app called balls. I would like the server to point to its index when I do manage.py runserver but I get this error:
Here's my urls.py:
from django.contrib import admin
from django.urls import include, path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('balls/', include('balls.urls')),
path('admin/', admin.site.urls),
]
urlpatterns += [
path('', RedirectView.as_view(url='balls/', permanent=True)),
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
I am also including the project structure. Please note that the string ball appears nowhere in my code (as per a search).
According to your screenshot, you're sending requets to http://127.0.0.1:8000/ball and this URL not found on given path path('balls/', include('balls.urls')) so try to go to this http://127.0.0.1:8000/balls

Django ModuleNotFoundError: No module named 'product'

I am absolute new to django and I have followed the example of Django documentation https://docs.djangoproject.com/en/3.0/intro/tutorial01/
but getting a problem in main project's urls.py file which is Module not found error pls help. Heres my main projects urls.py:
`from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('product.urls')),
path('admin/', admin.site.urls),
]

urls.py django 2.0.2 need parameters

i'm learning django and i'm making a blog tutorial but it's from older version that i have, i have version 2.0.2 and i'm not understand documentation my problem is that i dont know how configure my urls.py
this is my three proyect:
i need to put archive.html in 127.0.0.1:8000/ and this is my urls code
codigofacilito/blog.urls.py :
"""codigofacilito 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<br/>
from django.urls import path<br/>
from . import views<br/>
urlpatterns = [
path('admin/', admin.site.urls),
]
and codigofacilito/codigofacilito.urls.py:
from django.contrib import admin
from django.urls import path
from . import views
enter code here`urlpatterns = [
path('admin/', admin.site.urls),
]
from django.views.generic import TemplateView
urlpatterns = [
path('', TemplateView.as_view(template_name = 'archive.html')),
path('admin/', admin.site.urls),
]
put this in your project's urls.py, this will directly render the archive.html when you visit 127.0.0.1:8000/ in your browser.
but if you want to render data from backend in this html page then i suggest you to use views (function based , class based, etc..)
then you just have to import the views in url file and specify path for that.
from your_app.views import your_view
urlpatterns = [
path('/', your_view),
]

Django Project: namespace 'admin' isn't unique

on trying to run C:\Python34/python manage.py makemigrations, I get the following error: (following a tutorial from www.testandtrack.io)
Error
WARNINGS: ?: (urls.w005) URL namespace 'admin' isn't unique. You may not be able to reverse all URLS in this namespace
What precisely do I need to change and where do I need to look?
teachers/url.py
from django.contrib import admin
from django.urls import path
from django.urls import include, path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.teachers, name='teachers'),
]
url.py
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('main.urls')),
path('teachers/', include('teachers.urls')),
]
main/url.py
urlpatterns = [
path('admin/', admin.site.urls),
path('header/', views.header, name='header'),
path('', views.index, name='index'),
]
I've pasted the various url.py files above and imagine it's a problem somewhere there. could anyone please point me in the right direction, with an explanation please?
I've considered that I could/should remove
path('admin/', admin.site.urls),
from all but the urls.py file (root) .....when I do remove this, I don't get the same error, but I don't know if that will cause other problems and if this is the right thing to do?
You are declaring
path('admin/', admin.site.urls),
three times in your urls files. You just have to declare it once in the root urls.py of your project.
You are correct in that the error stems from repeating path('admin/', admin.site.urls), in all of your url.py files. It is normally only declared at the root level as others have pointed out.
Think of it like this - You wouldn't want to have a separate admin interface for each app, rather you would want to be able to manage all of your apps from one admin interface which is exactly what occurs when you have it only in the root urls.py file.
Also, although the apps should be modular and independent they still need to be connected to a project to work.
Set your main/urls.py as
from django.urls import path
from django.views.generic import TemplateView
urlpatterns = [
path(
"header/",
TemplateView.as_view(template_name="header.html")),
]
And fix this inside the main URLs file teachers/urls.py as follows:
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
urlpatterns = [
path(
'admin/',
admin.site.urls),
path('',
include('main.urls')),
]
it's because of multiple declarations of that admin path. remove those extra line path('admin/', admin.site.urls) line from urls.py file except the project's url.py
There is a repetition of an admin path
Search in the files urls.
and delete duplicate path