Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - issue with APPEND_SLASH and POST requests

Tags:

django

I am using Django 1.10, and my goal now is to make urls available both with and without trailing slash. To do this, I added slash to all my URLs in the URLConf files, and then set APPEND_SLASH variable value to True (well, this is the default value).

Now the problem is that external POST requests (which I can't control) yield the following error:

You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data. Change your form to point to 127.0.0.1:8000/Calendar/AddAccounts/ (note the trailing slash), or set APPEND_SLASH=False in your Django settings.

They mention this in Django doc, and yet after hours of surfing the net, I can't figure out how to address this issue.

I've also come across this question, but the proposed solution doesn't seem acceptable to me. It says I have to make the users call my URLs only with trailing slash. While I know that in other languages (C# for example) it is possible to enable both options

like image 610
Edgar Navasardyan Avatar asked Mar 24 '18 07:03

Edgar Navasardyan


1 Answers

It seems weird to me that you want to support both cases. Ideally you would want to redirect from non slash to slash(or the other way around if you want that) on the server level (nginx/apache/whatever you use) before the request hits Django.

Just choose a strategy and stick to it, so add the trailing slash to your form and never look back. :)

It's important to be consistent. https://www.branded3.com/blog/urls-trailing-slash-seo/

like image 84
JOSEFtw Avatar answered Oct 27 '22 01:10

JOSEFtw