Thursday, May 27, 2021

Re: How can I pass input value to view function without forms

Hello Boris,
      I was thinking of passing number from the input to view function call_me_when_ten()
index.html
...
<input type= number name = "numbered"/>
...

views.py
def call_me_when_ten(request):
    if request.post == 'POST':
          number = request.POST['numberid']
          if number == 10:
                 print('hello world')
    return render(request,'index.html')

I got this code from StackOverflow, but this isn't worked. Please, help me in solving out this problem.

On Wednesday, May 26, 2021 at 5:02:04 AM UTC+5:30 Boris Pérez wrote:
Hi!!! usually HttpResponseRedirects work with reverse
function...something like this
def myview(request):
return HttpResponseRedirect(reverse('arch-summary', args=[1945]))
where 'arch-summary' is the path name and args=[1945] the args it expects...
You need to modify also your urls.py to add tyhe name argument to your url...
Greetings

2021-05-25 0:57 GMT-04:00, Bhanu prasad Ch <bp35...@gmail.com>:
> Hello everyone,
> Please help me out in understanding how to pass the redirected view
> with some arguments like userid to connect the URLs in Django
> [image: Screenshot_2.png][image: Screenshot_3.png]
> When I am doing this way it is redirecting to the self page that is login.
> But I need the
> HttpResponseRedirect to redirect to the progress.
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/2ebc28b3-0e99-4ace-9868-aad10564a172n%40googlegroups.com.
>

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f17dd6c8-4228-46d4-b9f4-fb4059e5d536n%40googlegroups.com.

No comments:

Post a Comment