APPEND_SLASH skip per URL or per base_uri

244 views
Skip to first unread message

Val Neekman

unread,
Mar 13, 2014, 5:12:51 PM3/13/14
to django-d...@googlegroups.com
Some JavaScript frameworks(e.g. AngularJS) remove the ending slash before making a request.
If APPEND_SLASH = True, then the API would not be consumable by AngurlarJS.

Would it be a good idea to add options to disable the APPEND_SLASH behaviour per url(), or per a base_uri?

Example 1:
settings.py:
APPEND_SLASH = True

urls.py:
url(r'^profile', views.profile, name='profile', append_slash=False),

Example 2:
settings.py
APPEND_SLASH = True
APPEND_SLASH_EXCLUDE = ('/api/v1/', '/api/v2/', '/etc/)

What do you think?

If the answer is YES, then would it be too late to push a patch up for inclusion in 1.7?

Thanks,

Val

Aymeric Augustin

unread,
Mar 13, 2014, 5:18:37 PM3/13/14
to django-d...@googlegroups.com
On 13 mars 2014, at 22:12, Val Neekman <v...@neekman.com> wrote:

Would it be a good idea to add options to disable the APPEND_SLASH behaviour per url(), or per a base_uri?
url(r'^profile', views.profile, name='profile', append_slash=False),

Hi Val,

In my opinion this is too specific. The logic for APPEND_SLASH doesn’t require much code. Just write your own middleware or subclass Django’s middleware.

-- 
Aymeric.


Ryan Hiebert

unread,
Mar 13, 2014, 5:19:10 PM3/13/14
to django-d...@googlegroups.com
In your example, APPEND_SLASH


--
You received this message because you are subscribed to the Google Groups "Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/e01272a7-585f-42fe-85e5-8b0020aef882%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ryan Hiebert

unread,
Mar 13, 2014, 5:21:03 PM3/13/14
to django-d...@googlegroups.com
Sorry, auto-send.

In your example, APPEND_SLASH wouldn't add a slash, because the URL in the URLConf doesn't have a slash on it.

I figure you probably meant this, though:

url(r'^profile$', views.profile, name='profile', append_slash=False),

(with a dollar sign at the end of the regex pattern).

Val Neekman

unread,
Mar 13, 2014, 5:51:46 PM3/13/14
to django-d...@googlegroups.com

Val Neekman

unread,
Mar 14, 2014, 11:07:41 AM3/14/14
to django-d...@googlegroups.com
Hi Aymeric,

Localized solution is fine, but when I saw the number posts from people who were trying to find a solution to this, I thought, perhaps it would be a nice little enhancement to the APPEND_SLASH functionality.

Thanks,

Val

Ryan Hiebert

unread,
Mar 14, 2014, 11:25:09 AM3/14/14
to django-d...@googlegroups.com
On Fri, Mar 14, 2014 at 10:07 AM, Val Neekman <v...@neekman.com> wrote:

Localized solution is fine, but when I saw the number posts from people who were trying to find a solution to this, I thought, perhaps it would be a nice little enhancement to the APPEND_SLASH functionality.
 
You don't need to avoid APPEND_SLASH. Just remove the trailing slash from the URL pattern, and Django won't ever append a slash to the URL. Of course, then it also won't work if caller puts a slash at the end.

Shai Berger

unread,
Mar 19, 2014, 12:12:58 PM3/19/14
to django-d...@googlegroups.com
On Friday 14 March 2014 17:07:41 Val Neekman wrote:
> Hi Aymeric,
>
> Localized solution is fine, but when I saw the number posts from people who
> were trying to find a solution to this, I thought, perhaps it would be a
> nice little enhancement to the APPEND_SLASH functionality.
>

https://github.com/appliedsec/djangular#enforcing-the-end-slashes-of-your-angular-resources

It seems this can be handled adequately from the other side,
and a set of tools for using Django with AngularJS seems like
exactly the right place for such a tool.

So, I don't think this is a good addition to Django core.

Shai.
Reply all
Reply to author
Forward
0 new messages