Reputation: 7183
I just migrated to django 1.5 and I am facing a problem with the new policy regarding url language redirects, my old Ajax POST
to for example /search
end up being redirected to /en/search
with a GET
of course.
How to fix this (ideally without modifying too much code) ?
Upvotes: 0
Views: 552
Reputation: 7183
I came up with a solution, I named my ajax post urls like this:
url(r"^search_engine/ajax_form/$", ajax_form, name='ajax-search')
And in my template I did :
<form method="post" action="{% url 'ajax-search' %}" id="search-form">
And eventually in my script.js I did :
var form = $('#search-form');
$.ajax({
type: 'POST',
url: $(form).attr('action'),
dataType: 'json',
data : form.serialize(),
success: function(data) {
/*stuff*/
}
});
If there is a better way to do this in django 1.5 I would like to know.
EDIT: By the way this is painful when the URL has parameters.
Upvotes: 1
Reputation: 950
in urls.py for Ajax requests move urls to "patterns"
urlpatterns = patterns('',
# urls for Ajax etc
)
urlpatterns += i18n_patterns('',
# sites urls
)
Upvotes: 0