If you want to have an effect at the server without leaving the
current page, you'll find that Django itself does not do that.
Instead, you'll have to do one of:
- Use JavaScript in the page to make an Ajax or WebSockets
call to the server (handled by a Django view if you like) to tell
it to update the DB, or...
- Use Django "Channels" to communicate with the server via
WebSockets.
If you find yourself doing lots of Ajax calls to the server, you may
want to check out the Django REST Framework which makes it
easier to write Django views that accept Ajax calls and return
JSON data instead of returning full HTML pages.
Or, you can accomplish a similar effect via plain vanilla Django,
if you allow the button click to trigger a regular form submit, and
have the response look exactly like the original page, so it's not
obvious to the user that a full page request was done. But, it
sounds like you've already decided you don't want to do that.
--Fred
Fred Stluka -- mailto:fred@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.
Fred Stluka -- mailto:fred@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.
On 5/28/17 9:25 PM, shivendra bind wrote:
Hi,--I recently started learning Django. Please help me with following problem.Background:I am using Python 3.5 and Django 1.11.1.I have 2 model class, Album and Song. A song always references to an album.I am using class based views to perform CRUD operations.Problem:how to update single field (favorite album/song) without rendering any form? What it means is user should be able to click a button, which updates column is_favorite in database,without leaving the current page .Thanks
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bfde298e-0b3e-4de5-9097-2a83b6ade1d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment