9

I'm using django admin on my website. When I enter url without slash after admin (http://example.com/admin) I receive 404 error. I thought that django automatically added slash on the end of url. Of course when I enter url ended with slash it works fine. What I am doing wrong, or which settings I have to change. Thanks for any ideas.

2 Answers 2

11

Try setting APPEND_SLASH = True in settings.py.

On second thoughts, I think the default setting is True.

https://docs.djangoproject.com/en/dev/ref/settings/#append-slash

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for quick replay. I have put APPEND_SLASH into settings (commonmidelware also is putted) but unfortunately still the same. maybe mod_python has problem with redirecting from 'admin' into 'admin/'?
I noticed that this happend to all link on my website. not olny admin. When I enter section name not ended with slash, slash didn't add automatically (the difference is that I don't have 404 but it is coused by rule in urls.py)
Does this happen when you use django's built in webserver or only when you run on Apache?
Stop using mod_python. I don't know if that's the reason you're having problems, but support for mod_python is deprecated and will be removed in Django 1.5 (docs.djangoproject.com/en/dev/howto/deployment/modpython).
@lukasz can you tell what was the mistake because am having the same problem
|
3

Don't forget the CommonMiddleware in your settings.py:

It's important to remember that the APPEND_SLASH parameter works in conjunction with the 'django.middleware.common.CommonMiddleware'. So in order for it to work you should have the following in your settings.py:

MIDDLEWARE = [
    'django.middleware.common.CommonMiddleware',
]

You don't need to add the APPEND_SLASH in your settings.py because the default behavior is to redirect URLs that you've typed without and ending slash, for the correct one and as a pattern, you should always write your URLs with an ending slash, like:

urlpatterns = [
    path('hello/', views.hello_world),
]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.