how to pass another atributte beside request after render a template in django

i have a FormView1 and inside the method form_valid(self, form), i return codeview(self.request, form)

class LoginUser(RedirectAuthenticatedUserMixin, AjaxCapableProcessFormViewMixin,FormView):

template_name = "account/login.html"
form_class = FormularioLogin
success_url = reverse_lazy('inicio')

    def form_valid(self, form):
        success_url = self.get_success_url()
        try:
             return codieview(self.request, form)
       except ImmediateHttpResponse as e:
            return e.response

that way codeview can obtain all the methods of the formview1,

def codeview(request, form):
return render(request, template_name=‘codigo_login.html’, context={})

but if i render a template inside codeview i dont know how to pass the form atributte and receive it
in the next function of this way
def receive(request, form):

I’m not following what you’re trying to do here.

Always keep in mind that a view:

  1. Receives a request
    and then
  2. Returns a response

and the view exits at that time.

What is your core objective here? (Perhaps try to explain it from the user’s perspective, that might be easier.)

Ken

the class LoginUser is a Login Form, after the user write his credentials a code authentication is needed, so, before send the login request inside form_valid that is “return form.login(request, redirect_url=reverse(‘index’))”, i call my template where the user should write the code authentication, that is codeview(request, form), here i receive the method form.login(…) and the post method of the template “codigo_login.html” redirect me to {% url ‘receive’ %}.

how can i send alse the atributte form together with the request ?

class LoginUsuario(RedirectAuthenticatedUserMixin, AjaxCapableProcessFormViewMixin, FormView):
template_name = “account/login.html”
form_class = FormularioLogin
success_url = reverse_lazy(‘inicio’)

def form_valid(self, form):
    success_url = self.get_success_url()
    try:
          return codeview(self.request, form)
    except ImmediateHttpResponse as e:
        return e.response

now, in codeview

def codeview(request, form):
return render(request, template_name=‘code_login.html’, context={})

here in codeview i just send the request, but i dont know how to send the same form atributte

codeview redirect me to {% url ‘codeverification’ %}

so i need to receive the same atributte form in codeverification,to send the login request
def codeverificacion(request, form):
return form.login(request, redirect_url=reverse(‘index’))

Ok, let’s see if I’m following you now:

  1. User goes to your site, gets a Login Form
  2. User enters credentials, clicks “submit”
  3. You receive that form.
    1. Do you validate the entered credentials at that time?
  4. You send another form, requesting some additional code.
    1. Where does that credential come from? Is it something the user already knows in addition to their password?
  5. User enters that additional credential, clicks “Submit”.
  6. You receive and process that submission, and upon verification, direct the user to their final destination.

Am I understanding you correctly?

If so, then you’re looking at two separate views - this is not something done within a single view.

Side note: When you’re posting code, please enclose the code fragments between lines consisting only of three backtick - ` characters. That means you would have one line of ```, followed by your lines of code, followed by another line of ```.
Example:

# The line above this one is ```
def function(self):
    return self
# The line below this one is ```

As you can see, “fencing” your code like this allows it to maintain its formatting, making it much easier to read.

Ken

after submit de LoginForm the user receive a mail with the code and then submit that code in another template

thats why i’m trying to pass the form attribute , how can i receive that code of the other view and late send the login request in another view (form.login)?, i just need two pass the attribute/value ‘form’ between the views but render template doesn’t send more parameters than ‘request’

how can i pass ‘form’ after render the template?

its something like this
return render(request, form, template_name=’‘template.html’, context={}) but this isnt posible

the action{% url ‘receive’ %}

and

def receive(request, form):
form.login(…)

It might be easier at this point if you provide your complete views involved in this sequence. Talking in the abstract is not sufficient.

Also, please confirm whether or not the outline I provided above is the correct and complete desired sequence of events.

(To some degree, I’m getting the impression that we might be dealing with an “X/Y Problem”, and so I’d like to see the real code to try and get to what you’re really trying to accomplish.)

how can i show the real code?

Copy and paste the complete views here. Don’t edit anything out of it or try to summarize it. (Both views, the view where the initial login form is being displayed and the view handling the authentication code.)

(Also, please format it as described above: how to pass another atributte beside request after render a template in django)