213👍
Check the docs for include here.
What you’ve done is not an acceptable way of passing parameters to include. You could do:
url(r'^reviews/', include(('reviews.urls', 'reviews'), namespace='reviews')),
126👍
Django 1.11+, 2.0+
You should set the app_name in the urls file you are including
# reviews/urls.py <-- i.e. in your app's urls.py
app_name = 'reviews'
Then you can include it the way you are doing it.
Also, it might be worth noting what Django docs say here https://docs.djangoproject.com/en/1.11/ref/urls/#include :
Deprecated since version 1.9: Support for the app_name argument is
deprecated and will be removed in Django 2.0. Specify the app_name as
explained in URL namespaces and included URLconfs instead.
( https://docs.djangoproject.com/en/1.11/topics/http/urls/#namespaces-and-include )
- [Django]-How does django handle multiple memcached servers?
- [Django]-No URL to redirect to. Either provide a url or define a get_absolute_url method on the Model
- [Django]-Django-tables2: How to use accessor to bring in foreign columns?
43👍
Django 2.0 you should specify app_name in your urls.py, is not necessary to specify app_name argument on include.
Main Url file.
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('', include('apps.main.urls')),
path('admin/', admin.site.urls),
]
Included Url.
from django.urls import path
from . import views
app_name = 'main_app'
urlpatterns = [
path('', views.index, name='index'),
]
Then use use in template as
<a href="{% url main_app:index' %}"> link </a>
More details: https://code.djangoproject.com/ticket/28691
Django 2.0 Docs
- [Django]-How to get the currently logged in user's id in Django?
- [Django]-How do I POST with jQuery/Ajax in Django?
- [Django]-Table thumbnail_kvstore doesn't exist
4👍
I included a library not (fully) django 2.1 compatible yet (django_auth_pro_saml2). Hence I create a second file saml_urls.py
:
from django_saml2_pro_auth.urls import urlpatterns
app_name = 'saml'
Such that I could include the urls as:
from django.urls import include, re_path as url
urlpatterns = [
..., url(r'', include('your_app.saml_urls', namespace='saml')), ...
]
Hacky, but it worked for me, whereas the url(r'^reviews/', include(('reviews.urls', 'reviews'), namespace='reviews'))
did not.
- [Django]-Django: How to manage development and production settings?
- [Django]-Error when using django.template
- [Django]-Laravel's dd() equivalent in django
2👍
I am also face the same error in Django 2.2 and i solve it this way
urls.py file
urlpatterns = [
path('publisher-polls/', include('polls.urls', namespace='publisher-polls')),
]
polls/urls.py file
app_name = 'polls'
urlpatterns = [
path('', views.IndexView.as_view(), name='index')
]
example use of namespace in calss based view method
def get_absolute_url(self):
from django.urls import reverse
return reverse('polls.index', args=[str(self.id)])
example use of namespace in templates
{% url 'polls:index' %}
Here polls:index mean app_name[define in polls/urls.py file]:name[define in polls/urls.py file inside path function]
their official which is pretty good you can check for more info namespace_django_official_doc
- [Django]-How do you serialize a model instance in Django?
- [Django]-Django: Multiple forms possible when using FormView?
- [Django]-Django – makemigrations – No changes detected
0👍
Find unused files or directories in APP (reviews) directory, and detete this items !
- [Django]-Pytest.mark.parametrize with django.test.SimpleTestCase
- [Django]-Use Python standard logging in Celery
- [Django]-Django DRF with oAuth2 using DOT (django-oauth-toolkit)
0👍
In project level urls.py
path('',include('appname.urls'), namespace= 'test')
Now in in your app level urls.py
app_name = 'test'
path('',views.index, name= 'home')
Long story short is, You have to provide "app_name" in your app level urls and that same name should be your namespace name at project level url
- [Django]-Django REST Framework: adding additional field to ModelSerializer
- [Django]-Django: Grab a set of objects from ID list (and sort by timestamp)
- [Django]-How do you change the collation type for a MySQL column?