I don't think it is a a good idea to call a view from another view, but if
you have an underlying function that used to be a view, and you want to
call it to do the secondmethod, then that's a good way to begin to do more
with Django. Another good way is to practice using the generic
class-based views until they begin to make sense.
One of my developers used to "assume" the request.method was 'POST' in one
function, called search_result, and she also had a search_request method
which was also a view:
def search_request(request):
assumes GET ...
def search_result(request):
assumes POST ...
I created a new function search_view(), and made that the view, the other
two are just functions:
def search_view(request):
if request.method == 'GET':
return search_request(request)
elif request.method == 'POST':
return search_result(request)
else:
return HttpResponseNotAllowed();
On Tuesday, June 18, 2019 at 9:29:44 AM UTC-4, Sebastian Jung wrote:
>
> Hello,
>
> I have a view like this:
>
> def secondmethod(request,entry):
>
> if request.method='POST':
>
> return request.POST.get('selection')
>
>render(request,'eintrag.html','entry':entry)
>
>
> def test(request):
>
> if request.method='POST':
>
> queryresult = model.objects.all()
> for entry in queryresult:
> eintrag = secondmethod(request,entry)
>
>render(request,'homepage.html')
>
>
> This is a easy example. I call the view test, in for loop i want to call
> the view secondmethod several times. In function secondmethod eintrag.html
> render and the selection return back to test. Then next row from
> queryresult is submit to secondmethod. Is this possible?
>
>
>
>
>
>
--
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+unsubscr...@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/d6784c0d-28b4-4b34-8b5c-2ace163199e4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.