Hello I'm having a problem when trying to run server from an Django 2.0 old project.
this is the error:
File "/usr/lib/python3.7/site-packages/django/urls/conf.py", line 39, in include
'Specifying a namespace in include() without providing an app_name
django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.'
this is my urls.py
from django.conf.urls import url, include
from django.contrib import admin
from apps.sysgrub.views import LoginUser, LogoutUser
app_name = 'apps'
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^alumno/', include ('apps.alumno.urls', namespace="alumno")),
url(r'^grupo/', include ('apps.grupo.urls', namespace="grupo")),
url(r'^maestro/', include ('apps.maestro.urls', namespace="maestro")),
url(r'^rol/', include ('apps.rol.urls', namespace="rol")),
url(r'^sysgrub/', include ('apps.sysgrub.urls', namespace="sysgrub")),
url(r'^$', LoginUser),
url(r'^logout/$', LogoutUser),
]
and my urls by app
urlpatterns = [
url(r'^index$', index),
url(r'^horarios$', horarios),
url(r'^listar$', Alumno_grupoList.as_view(), name='alumno_listar'),
url(r'^agregar$', AlumnoCreate.as_view(), name='add_student'),
]
thank you so much for your help greetings.
The error describes the resolution please remove app name from the urls.py as below
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^alumno/', include ('alumno.urls', namespace="alumno")),
url(r'^grupo/', include ('grupo.urls', namespace="grupo")),
]
Related
I am building an app using django and notice that some new urls that i have created, the list is provided below are not being found.
I read somewhere that the slug might be the reason django cannot found the urls but i am not sure
main urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path(config("ADMIN_URL"), admin.site.urls),
path("", include("core.urls", namespace="core")),
]
application urls.py
from django.contrib import admin
from django.urls import path, include
from . import views
app_name = 'core'
urlpatterns = [
path('index/', views.index, name='index'),
path('home/', views.home, name='home'),
path('home/<slug:slug>/', views.user_lessons_details, name='user-lessons-details'),
path('home/join-transaction/', views.user_lessons_join_transaction, name='user-lessons-join-transaction'),
path('home/start-transaction/', views.new_test_epoint, name='new-test-epoint'),
path('home/draft/<slug:slug>/', views.user_lessons_core_action, name='user-lessons-draft'),
path('teachers/lessons/create/', views.merchant_lessons_create, name='teachers-lessons-create'),
path('teachers/lessons/list/', views.teachers_lessons_list, name='teachers-lessons-list'),
path('teachers/lessons/<slug:slug>/', views.teachers_lessons_details, name='teachers-lessons-details'),
path('teachers/lessons/<slug:slug>/update/', views.teachers_lessons_update, name='teachers-lessons-update'),
path('teachers/lessons/<slug:slug>/delete/', views.teachers_lessons_delete, name='teachers-lessons-delete'),
path('teachers/drafts/create/', views.teachers_core_actions_create, name='teachers-drafts-create'),
path('teachers/drafts/list/', views.teachers_core_actions_list, name='teachers-drafts-list'),
path('teachers/drafts/<slug:slug>/', views.teachers_core_actions_details, name='teachers-drafts-details'),
path('teachers/drafts/<slug:slug>/update/', views.teachers_core_actions_update, name='teachers-drafts-update'),
path('teachers/drafts/<slug:slug>/delete/', views.teachers_core_actions_delete, name='teachers-drafts-delete'),
path('teachers/home/list/', views.teachers_home_list, name='teachers-home-list'),
path('teachers/home/<slug:slug>/', views.teachers_home_details, name='teachers-home-details'),
path('teachers/home/create/course/', views.teachers_home_transaction_quote, name='teachers-home-create-course'),
path('teachers/home/create/something/', views.teachers_home_create_transaction, name='teachers-home-create-something'),
path('teachers/home/create/fields-selection/', views.teachers_home_fields_selection, name='teachers-home-fields-selection'),
# ALL THE NEW URLS BELOW return NOT FOUND in django no matter what i do
path('teachers/home/account/settings/', views.teachers_settings, name='teachers-settings'),
path('teachers/account/settings/update-password/', views.teachers_settings_update_password, name='teachers-settings-update-password'),
path('teachers/account/payments/', views.teachers_payments, name='teachers-payments'),
path('teachers/account/payments/update/', views.teachers_payments_update, name='teachers-payments-update'),
path('teachers/account/analytics', views.teachers_analytics_stuff, name='teachers-analytics-stuff')
]
How can i possibly solve this urls not found issue in django?
Please dont mind the urls meaning
I have the following urls.py in my project dir,
Main project urls.py
from django.contrib import admin
from django.urls import path, include
from . import views
urlpatterns = [
path('', views.render_calculator, name='render_calculator'),
path('calculator/', views.render_calculator, name='render_calculator'),
path('disclaimer/', views.render_disclaimer, name='render_disclaimer'),
path('cookiepolicy/', views.render_cookiepolicy, name='render_cookiepolicy'),
path('privacypolicy/', views.render_privacypolicy, name='render_privacypolicy'),
path('dashboard/', views.render_dashboard, name='render_dashboard'),
path('about/', views.render_about, name='render_about'),
path('admin/', admin.site.urls),
path(r'^', include('accounts.urls'))
]
Now I created a new app accounts (I added it to my apps in settings.py) where I would like to store the urls of that app in its own dir like so:
Accounts app urls.py
from . import views
from django.urls import path
urlpatterns = [
path('register/', views.render_register, name='render_register'),
]
Accounts app views.py:
from django.shortcuts import render
def render_register(request, template="register.html"):
return render(request, template)
However, this configuration throws me this error:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/register
Using the URLconf defined in CFD.urls, Django tried these URL patterns, in this order:
[name='render_calculator']
calculator/ [name='render_calculator']
disclaimer/ [name='render_disclaimer']
cookiepolicy/ [name='render_cookiepolicy']
privacypolicy/ [name='render_privacypolicy']
dashboard/ [name='render_dashboard']
about/ [name='render_about']
admin/
^
The current path, register, didn't match any of these.
Where is the missing piece?
You are using path() with the regex r'^' which is causing your problem.
In order to define a path with a regex, you need to use re_path.
So change it to the following line:
re_path(r'^', include('accounts.urls'))
or you can use
path('', include('accounts.urls'))
Change this.
path(r'^', include('accounts.urls')) to
path('', include('accounts.urls'))
I am having a difficult time understanding the connection between app_name and namespace.
consider the project level urls.py
from django.urls import path, include
urlpatterns = [
path('blog/', include('blog.urls', namespace='blog')),
]
consider the app level (blog) urls.py
from django.urls import path
from . import views
app_name = 'blog'
urlpatterns = [
path('', views.post_list, name='post_list'),
path('<int:year>/<int:month>/<int:day>/<slug:post>/', views.post_detail, name='post_detail'),
]
if I comment out app_name, I get the following.
'Specifying a namespace in include() without providing an app_name '
django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in
the included module, or pass a 2-tuple containing the list of patterns and app_name instead.
If I rename app_name to some arbitrary string, I don't get an error.
app_name = 'x'
I've read the documentation but its still not clicking. Can someone tell me how/why app_name and namespace are connected and why are they allowed to have different string values? Isn't manually setting app_name redundant?
try removing app_name='blog'
In your case you should be using:
'blog:post_list'
and
'blog:post_detail'
You can also remove the namespace='blog' in your first url like so:
urlpatterns = [
path('blog/', include('blog.urls')),
]
and then in your templates you can reference the urls without the 'blog:.....':
'post_list'
'post_detail'
try using tuple.
urlpatterns = [
path('blog/', include(('blog.urls', 'blog'))),
]
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"
I have this code in one file called urls.py
from django.conf.urls import url
from django.contrib import admin
from myblog import urls
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'', urls),
]
Im trying to redirect to another file in a module called myblog which contains another file called urls.py with the following code:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.post_list, name='post_list'),
]
my views file which contains post_list method is as follows:
from django.shortcuts import render
def post_list(request):
return render(request,'myblog/post_list.html', {})
The result is that i keep getting the following error message:
module 'myblog.urls' from 'path\to\python\file\urls.py' is not a callable or a dot-notation path
Can anyone please explain to me where i am getting it wrong. I am new to django and python and i am using a tutorial from DjangoGirls.com. They use Django 1.8 and i have Django 1.9 installed.
Looking at the tutorial, uou can see that you have forgotten to use include.
First you have to add the import
from django.conf.urls import include, url
Then change the url pattern to:
url(r'', include('blog.urls')),
Be careful that you are using the correct module name - you have myblog, but the tutorial has blog.
You need to include the urls.py to link them
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'', include(urls, namespace='MyOtherapp')),
]
Note: I've also added a namespace here, its not required, it just helps when your using the url template tag.