title: Can you make a view that redirects the user to another app based on a random variable?
body: <p>as the title says, I want to create a functions that redirects the user to another app based on a random variable.</p>
  <p>I created a function and gave a random value to a variable that calls the corresponding view of another app, but only the first value of the random range works fine, while the other get an error at the form validation.</p>
  <p>contest.views:</p>
  <pre class="lang-py prettyprint-override"><code>from django.shortcuts import render
  from django import forms
  import random
  from user.models import UserProfileInfo
  
  from .problems.problem5_1contest.views import problem_one
  from .problems.problem5_2contest.views import problem_two
  from .problems.problem5_3contest.views import problem_three
  
  def contestproblem1(request):
      return problem_one(request)
  def contestproblem2(request):
      return problem_two(request)
  def contestproblem3(request):
      return problem_three(request)
  
  def contest(request):
      k = random.randint(1,3)
      if(k == 1):
          return contestproblem1(request)
      if(k == 2):
          return contestproblem2(request)
      if(k == 3):
          return contestproblem3(request)
  </code></pre>
  <p>problem5_1contest.views:</p>
  <pre class="lang-py prettyprint-override"><code>from django.shortcuts import render
  from django import forms
  from .forms import ProblemOneForm
  from .models import ProblemOneContest
  
  from user.models import UserProfileInfo
  # Create your views here.
  
  def wrong(request):
      return render(request, 'problem5_1contest/wrong.html')
  
  def correct(request):
      return render(request, 'problem5_1contest/correct.html')
  
  
  def problem_one(request):
      form = ProblemOneForm()
      form.fields['first'].widget = forms.HiddenInput()
      form.fields['second'].widget = forms.HiddenInput()
      form.fields['solution'].widget = forms.HiddenInput()
  
      if request.method == 'POST':
          form = ProblemOneForm(request.POST)
  
          if form.is_valid():
              form.save(commit=True)
              if(int(form.cleaned_data['answer']) == int(form.cleaned_data['solution'])):
                  return render(request, 'problem5_1contest/correct.html')
              else:
                  return render(request, 'problem5_1contest/wrong.html')
          else:
              print('ERROR')
  
      return render(request, 'problem1/problem1.html',{ 'form':form } )
  </code></pre>
  <p>problem5_2contest.views:</p>
  <pre class="lang-py prettyprint-override"><code>from django.shortcuts import render
  from django import forms
  from .forms import ProblemTwoForm
  from .models import ProblemTwoContest
  
  from user.models import UserProfileInfo
  # Create your views here.
  
  def wrong(request):
      return render(request, 'problem5_2contest/wrong.html')
  
  def correct(request):
      return render(request, 'problem5_2contest/correct.html')
  
  
  def problem_two(request):
      form = ProblemTwoForm()
      form.fields['solution'].widget = forms.HiddenInput()
  
      if request.method == 'POST':
          form = ProblemTwoForm(request.POST)
  
          if form.is_valid():
              form.save(commit=True)
              if(int(form.cleaned_data['answer']) == int(form.cleaned_data['solution'])):
                  return render(request, 'problem5_2contest/correct.html')
              else:
                  return render(request, 'problem5_2contest/wrong.html')
          else:
              print('ERROR')
  
      return render(request, 'problem2/problem2.html',{ 'form':form } )
  </code></pre>
  <p>problem5_3contest.views:</p>
  <pre class="lang-py prettyprint-override"><code>from django.shortcuts import render
  from django import forms
  from .forms import ProblemThreeForm
  from .models import ProblemThreeContest
  
  from user.models import UserProfileInfo
  # Create your views here.
  
  def wrong(request):
      return render(request, 'problem5_3contest/wrong.html')
  
  def correct(request):
      return render(request, 'problem5_3contest/correct.html')
  
  
  def problem_three(request):
      form = ProblemThreeForm()
  
      form.fields['first_digit_one'].widget = forms.HiddenInput()
      form.fields['first_digit_two'].widget = forms.HiddenInput()
  
      form.fields['second_digit_one'].widget = forms.HiddenInput()
      form.fields['second_digit_two'].widget = forms.HiddenInput()
      form.fields['second_digit_three'].widget = forms.HiddenInput()
  
      form.fields['third_digit_one'].widget = forms.HiddenInput()
      form.fields['third_digit_two'].widget = forms.HiddenInput()
  
      form.fields['answer_digit_one'].widget = forms.HiddenInput()
      form.fields['answer_digit_two'].widget = forms.HiddenInput()
      form.fields['answer_digit_three'].widget = forms.HiddenInput()
  
      if request.method == 'POST':
          form = ProblemThreeForm(request.POST)
  
          if form.is_valid():
              form.save(commit=True)
              if(int(form.cleaned_data['answer']) != int(form.cleaned_data['answer_digit_one']) + int(form.cleaned_data['answer_digit_two']) + int(form.cleaned_data['answer_digit_three'])):
                  return render(request, 'problem5_3contest/wrong.html')
              else:
                  return render(request, 'problem5_3contest/correct.html')
          else:
              print('ERROR')
  
      return render(request, 'problem3/problem3.html',{ 'form':form } )
  </code></pre>
  <p>urls.py:</p>
  <pre><code>from django.contrib import admin
  from django.urls import path, include
  from django.views.generic import TemplateView
  
  from user import views
  from classes.views import class5, class6, class7, class8, classes
  
  from contest.views import contest
  
  
  urlpatterns = [
      path('admin/', admin.site.urls),
      path('', include('pwa.urls')),
      path('register/',views.register,name='register'),
      path('login/',views.user_login,name='login'),
      path('logout/', views.user_logout, name='logout'),
      path('home/', views.index, name='home'),
      path('classes/', classes, name='classes'),
      path('class5/', class5, name='class5'),
      path('class6/', class6, name='class6'),
      path('class7/', class7, name='class7'),
      path('class8/', class8, name='class8'),
  
      path('contest/', contest, name='contest'),
  
  ]
  </code></pre>
  <p>contest.urls.py:</p>
  <pre class="lang-py prettyprint-override"><code>from django.contrib import admin
  from django.urls import path, include
  from django.views.generic import TemplateView
  
  from contest.problems.problem5_1contest.views import problem_one as contestproblem1
  from contest.problems.problem5_2contest.views import problem_two as contestproblem2
  from contest.problems.problem5_3contest.views import problem_three as contestproblem3
  
  urlpatterns = [
      path('contest/class5/problemone', contestproblem1),
      path('contest/class5/problemtwo', contestproblem2),
      path('contest/class5/problemthree', contestproblem3),
  ]
  
  </code></pre>