Answer the question
In order to leave comments, you need to log in
How to handle clicking on a django link?
I started learning django, a question arose
I am writing a simple text-based web game
I have a "Fights" page against other players (The system is extremely simple. We click on the "attack" button, we calculate who won and display by the formula, without any visualization)
There is a hero model , with its characteristics (which returns the ID that I use to generate the link url )
urls.py
urlpatterns = [
path('', main_page,name='main_page'),
path('swap-hero/', swap_hero, name='swap-hero'),
path('store/', store, name='buyhero'),
path('store/<int:id>',buyhero,name='buyhero'),
path('profile/',profileUrl,name='profileUrl'),
path('fight/',fightPage,name='fightPage'),
path('buff/',buffHero,name='buffHero'),
path('castle/',UserCastle,name='UserCastle'),
path('fight/<int:id>',fightPage,name='makefight'),
]
<a href="fight.get_absolute_url">Напасть</a>
Answer the question
In order to leave comments, you need to log in
I didn't find anything concrete even on the theory
on the fight.html page, add id attributes to the links (unique, by itself) and put an on("click") handler using, for example, jQuery at the end of the page. And let this onclick execute an AJAX request of the type you need. So you don’t have to reload the page and queries can be built as you need.
And, by the way, it's
not very correct...
But you probably already read this in the documentation...
And, yes, the "regular" view does what it needs - everything you want :-)
Accept POST requests - so definitely can
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question