Reputation: 27
I want to make the url go as {% url 'namespace:name' %} but it don't work! I did everything according to the documentation, but all my attempts were in vain.
My CartDetail.html
..........
</tr>
</tbody>
</table>
<p class="text-right">
<button href="{% url 'shop:ProductList'%}" class="btn btn-info">Продолжить Шопинг</button>
<button href="#" class="btn btn-danger">Оформить заказ</button>
</p>
</div>
{% endblock %}
My shop/urls.py
from django.contrib import admin
from django.urls import path,re_path
from . import views
urlpatterns = [
re_path(r'^(?P<category_slug>[-\w]+)/$', views.ProductList, name='ProductListByCategory'),
re_path(r'^(?P<id>\d+)/(?P<slug>[-\w]+)/$', views.ProductDetail, name='ProductDetail'),
re_path(r'^$', views.ProductList, name='ProductList'),
]
And my main url.py
from django.contrib import admin
from django.urls import path, include, re_path
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
re_path(r'^cart/', include(('cart.urls', 'cart'), namespace='cart')),
path('', include(('shop.urls', 'shop'), namespace='shop')),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
What should I to do
Upvotes: 0
Views: 92
Reputation: 9325
from the docs:
path('publisher-polls/', include('polls.urls', namespace='publisher-polls'))
from your code:
path('', include(('shop.urls', 'shop'), namespace='shop'))
Upvotes: 1
Reputation: 5785
In main urls.py
path('', include('shop.urls', namespace='shop')),
In shop/urls.py
add
app_name = 'shop'
Now, you can use,
"{% url 'shop:ProductList' %}" # spaces are necessary
Upvotes: 0