Q:

Pass URL parameter to form value Django

I'm trying to set the value of a form input to the url, then redirecting to another page with another form using the information in the url parameter and passing another value of another input to the url. 
Let's say that my url is page1/value1/page2/value2 
Where value1 comes from the first form and value2 from the second form in the second page. 
Using this code I can get the first value in the url, but somehow I can't save the form information to the database and set the other value in the url. 
class Acceso(FormView):
    template_name = 'codigo_zona.html'
    form_class = AccesoForm

    def form_valid(self, form):
        zona_code = form.cleaned_data.get('codigo_acceso')
        return redirect('registro', zona_code)

class AccesoDetails(View):
    def get(self, request, zona_code):
        zona = Zona.objects.filter(codigo_acceso=zona_code).first()

        if request.method == 'POST':
            zona_id = zona.pk
            range_start = 10 ** (6 - 1)
            range_end = (10 ** 6) - 1
            access_code = randint(range_start, range_end)
            form = RegistroResidenteForm(request. POST)
            if form.is_valid():
                registro_residente = form.save(commit=False)
                registro_residente.zona_residencial.pk = zona_id
                registro_residente.codigo_acceso = access_code
                registro_residente.status_activacion = False
                registro_residente.save()
        else:
            form = RegistroResidenteForm()

        context = {
            'zona': zona,
            'form': form
        }
        return render(request, 'registro_residentes.html', context)

I get the error Method not allowed (Post): HTTP/1.1 405 0 when submiting the second form, so I never see the second value in the url. 

A:

Django generic view (View) is work with get method and form submitting is post method,
that's why django raising error, you can use CreateView or FormView also you can use function based view instead of using Class Based View

