Thank you for your response! I am trying to follow AJAX tutorials, and I keep running into an issue with the URLConfs. My current admin and index page use something like this:
-- urlpatterns = [
url(r''^admin/', include(admin.site.urls)),
]
But the when implementing AJAX, everything has said to use something like this:
urlpatterns = ('',
url(r'^ajac$', 'views.ajax')
)
I have tried conforming one to the other format, and tried doing them in separate entities, using a urlpatterns list and an extrapatterns list that calls patterns. Neither actually worked, and I am unsure how to combine the two.
On Wednesday, July 22, 2015 at 6:15:39 PM UTC-7, Alex Heyden wrote:
On Wednesday, July 22, 2015 at 6:15:39 PM UTC-7, Alex Heyden wrote:
A fair bit of this is Javascript, which, strictly speaking, is outside the scope of Django.From what you're saying, it sounds like your button does two things: make a backend database change and make a frontend display change. Ultimately, the action starts with a Javascript event handler. On button click, do work.On the Django side, you want a view that will capture the change. There's more than a few ways to do this, but if you're just talking about a one-and-done like this and you don't want a bunch of extra libraries, I'd make a simple, dedicated view that takes whatever parameters you need to specify the correct boolean field on POST and returns a JSON response to the effect of {success: [true|false], reason: 'failure reason, if any'}. Don't forget to update your urls.py to reflect the new view.On the Javascript side, in the registered function, you write code that both posts to your Django view in an Ajax call and, if successful, makes the display change.On Wed, Jul 22, 2015 at 5:35 PM, Jake Rudolph <jidru...@gmail.com> wrote:I am trying to make a button on the index page that changes the boolean field of my object, and then displays that object in a different place on the page. I am not sure what to put as the action for this button, and where to put and call the function that will actually change the value in the database.--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/564ecb34-8176-474a-8175-eb1c5b134522%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b63e2910-02aa-4bc6-8982-71b4ff6d3ddc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment