Django No Redirect

I have a flash file that calls the url: http://test.com/savethis/123456/

I just want my view to store “123456” in the database and not return anything.

After saving the values, what should I do? If I redirect it, it changes the page and that is bad. I could make a page, but I don't want to. I just want it to end and there are no errors.

+4
source share
2 answers

Make sure that URLConf points to the desired view function and write something like:

from django.http import HttpResponse from my_models import MyModel def myview(request, number): my_model = MyModel(my_field = number) my_model.save() return HttpResponse() 

An empty HttpResponse at the end returns a 200 OK status code, so the browser or other server that connects to your endpoint knows that the request has been completed.

+14
source

It looks like you are in a view function, which means that someone issued an HTTP request for something that you have to answer, so you can't just do nothing.

Return error code or return HttpResponse . You can simply return an empty OK response (i.e., return an HTTP 200 response):

 from django.http import HttpResponse def myview(request): return HttpResponse() 
+3
source

Source: https://habr.com/ru/post/1299301/


All Articles