1

I'm looking to capture and save the state of a page (Django template + backend) after the user makes some modifications (through JQuery) to the appearance of the page. Now that I've gotten hold of the innerHTML using a JS variable, I need to send it over to the Django view that will do the saving. How do I call this Django view and pass it the JS variable?

P.S: First ever question on stackoverflow, please let me know if the question isn't clear or is improperly formatted.

1 Answer 1

1

Handiest way to get started is to first make a proper form and a django view that reacts to it ("request.post"). The form should have fields for whatever you're changing in the page.

Next up, submit that form's variables from your page with jquery.ajax.

So the idea is to isolate the various problems:

  • What should be the form parameters?

  • Get a view running that makes the actual changes.

  • Get the javascript working.

Sign up to request clarification or add additional context in comments.

5 Comments

The page is a database dump where the user modifies the location of certain items with a JQuery draggable element. Is there a specific reason you're talking about forms? I feel I'm missing something here. Can you elaborate a bit? Thanks!
@Arish behind the scenes, that dragging is actually changing some attribute of the items, and you have to save that, don't you? Reinout is suggesting that you isolate this, by building a form and doing the work explicitly first, and only then emulating this with js.
@AdrianoVaroliPiazza Exactly! I see the sense behind the approach Reinout suggested, but I'm still trying to figure out what the "attribute" is that gets changed when I drag the item. Any ideas?
Well, you say "the user makes some modifications", so I don't know what it is you want to change as you're not very specific :-) You say "innerHtml", so perhaps you mean a bit of html? If so, make a form with a textfield in which you can paste the html. Later on, make this transparent behind-the-scenes with javascript. But I'm just guessing here.
I apologize about not being clear enough! I found that innerHTML was not at all what I thought it would be (HTML after the JS modifications). I'm eventually now grabbing final offset positions of each of the divs and sending them off to Django to store. To give you the broader picture of what I want to do, I'm attempting to store the user's preferred layout of a page (which they've modified with JQuery) so I can display it back later whenever they login. Reinout and Adriano, Thank you both for helping out!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.