views:

82

answers:

2

I have a flash file which calls a url like: http://test.com/savethis/123456/

I just want my view to save "123456" in the database and return nothing.

After saving the values what do I do? If I redirect it it changes the page and that's bad. I could render a page, but I don't want to. I just want it to end and not throw any errors.

+1  A: 

It sounds like you're in a view function, which means someone's issued an HTTP request for something, which you have to respond to, so you can't just do nothing.

Either return an error code, or return an HttpResponse. You could just return an empty OK response (i.e. return HTTP response 200):

from django.http import HttpResponse

def myview(request):
    return HttpResponse()
Dominic Rodger
+4  A: 

Make sure your URLConf points to your 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()

The empty HttpResponse at the end there sends back a status code of 200 OK so that the browser or other server that connects to your endpoint knows the request was completed.

Gabriel Hurley
That should solve it :D basically I'm in flash so I think I would just ignore the response and it will work fine :) Thanks for the help.
Fahim Akhter
Doing that thing from flash with navigateUrl is not really working. It gives me a pop up instead of doing it silently in the background.
Fahim Akhter