python - How to pass the values from the template as an argument to the function in views? -
i want input entered user in template pass arguments function imported views.py ..this part of template.
<form action="#" method="post"> {% csrf_token %} ratings: <input type="number" name="rate" step="0.1" min="1" max="5"><br> <input type="submit" value="submit" name="mybtn"> </form>
this function have used import function , pass values arguments.
def request_page(request): users_id = request.user.id + 671 if (request.post.get('mybtn')): updater.rate_movie(672, 6251, float(request.post['rate']))
according comments above should work:
<form method="post">{% csrf_token %} ratings: <input type="number" name="rate" step="0.1" min="1" max="5"><br> <input type="submit" value="submit" name="mybtn"> </form>
then in views.py
:
def request_page(request): users_id = request.user.id + 671 if request.method == 'post': updater.rate_movie(672, 6251, float(request.post['rate'])) return render(request, 'path/to/template.html')
Comments
Post a Comment