19👍
APPEND_SLASH doesn’t happen unconditionally — it only comes into effect if, after trying all existing URL patterns (and the associated view, if one matches), Django is about to return a 404.
If that’s the case, and the original request didn’t have a slash at the end, then Django checks to see whether any URL patterns would match with a trailing slash. If so, it issues an HTTP redirect.
If any of your URL patterns match the original request (without the slash), then Django will try that one first. If that raises an exception, then you will see it (I suspect that this is what is happening). Django won’t ever get to issue the redirect.
4👍
If you have added some of your own middleware, the order of the middleware is important. I had a similar case where the slash was working before and adding a middleware item broke it. After switching the order, everything started working again.
- Pycharm Django Debugging is really slow
- Get all templates django detects from TEMPLATE_LOADERS and TEMPLATE_DIRS
- Django REST Framework: Generics or ModelViewSets?
- Truncated or oversized response headers received from daemon process
3👍
This will surely fix your problem. You can give the url with or without a trailing slash, it will give you the same required result.
In the urls file,
urlpatterns = patterns('', url(r'^allvideo/?$','my.views.allvideo'))
Add question mark after the trailing slash.
When you enter an url it will first check with the trailing slash or it would match it without the trailing slash and in either case will give you the same response. Hope this was of some help to you. Happy Coding.
- _reverse_with_prefix() argument after * must be an iterable, not int
- Whats the best way to duplicate data in a django template?
- Using Pre_delete Signal in django
- Django: prefetch related objects of a GenericForeignKey
1👍
It might be caused by one of your apps having a slug on it’s own. Django will try to match the non-trailing slash version to the slug. For example:
In your root url.py
urlpatterns = [
path('admin/', admin.site.urls),
path("register/", include("user_register.urls")),
path('',include("django.contrib.auth.urls")),
path('', include("app.urls")),]
In your app.urls:
urlpatterns = [
path("", views.Index.as_view(), name="index"),
path("<slug:slug>", views.AppView.as_view(), name="app"),]
In this case http://mysite/register will not redirect because Django first looks for the slug in app.urls to fix it you have to prefix the slug with something. For example:
urlpatterns = [
path("", views.Index.as_view(), name="index"),
path("app/<slug:slug>", views.AppView.as_view(), name="app"),]
- Django request Post json
- Django –CSRF token missing or incorrect
- Using a Django variable in a CSS file
0👍
Not sure what is the root cause, but these might help you to go around it or narrow it down:
(1) Have you tried either using the actual view function as an argument (instead of a string):
from my.views import allvideo
urlpatterns = patterns('', url(r'^allvideo/$',allvideo))
(2) Or skip using the url-function:
urlpatterns = patterns('', (r'^allvideo/$','my.views.allvideo'))
- Django `SECRET_KEY` settings
- Python Fabric: How to handle arbitrary remote shell prompt for input?
- Setting up Yeoman with Django
- Django Template – New Variable Declaration
-1👍
Even if it seems unbelievable, I had the same issue and just restarting the development server fixed it. Just to remember:
python manage.py runserver
- How do i use validation in admin.py while overriding save_model() function?
- Django: how to hide/overwrite default label with ModelForm?
- Django AttributeError: 'DatabaseOperations' object has no attribute 'select'
- How to solve double curly brackets issue when using Vue + Django template language?
- What does this operator means in django `reduce(operator.and_, query_list)`