0

I would like to fill out a form on an html page and then send the completed form to another html to check the entries there and then save them. I just don't know how to send the data from one html to another. I ask you to help me. Thanks

question.html
here is the form
{% extends 'dependencies.html' %}

{% block content %}

<div class="jumbotron container row">
    <div class="col-md-6">
        <h1>Add Question</h1>
        <div class="card card-body">
           <form action="" method="POST" id="form">
              {% csrf_token %}
                {{form.as_p}}
                <br>
               <input type="submit" name="Submit">
           </form>

        </div>
    </div>


</div>

{% endblock %}

approve_questions.html

I wanna to get the content from question.html here

currently empty 

views.py

def questions(request):
        form = addQuestionform()
        if (request.method == 'POST'):
            form = addQuestionform(request.POST)
            if (form.is_valid()):
                form.save(commit=False)
                html = render_to_string("notification_email.html")
                send_mail('The contact form subject', 'This is the message', 'noreply@codewithstein.com', ['example@gmail.com'],
                          html_message=html)


                return redirect("login")


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


def approve_questions(request):
    return render(request, "approve_question.html")
  • Does this answer your question? [Transfer data from one HTML file to another](https://stackoverflow.com/questions/17502071/transfer-data-from-one-html-file-to-another) – Manoj Tolagekar Dec 05 '22 at 05:40
  • Does this answer your question? [Forward content from one html to another html via views.py](https://stackoverflow.com/questions/74690697/forward-content-from-one-html-to-another-html-via-views-py) – Abdul Aziz Barkat Dec 06 '22 at 04:35
  • Please don't post the same question multiple times. If you need to clarify anything, you can [edit] your question. – Abdul Aziz Barkat Dec 06 '22 at 04:37

1 Answers1

0

If I understand your questions correctly.

You can pass through passing form variable into approved_questions views. Likewise

views.py

def approve_questions(request, form):
    context = {'form': form}
    return render(request, "approve_question.html", context)


def questions(request):
        form = addQuestionform()
        if (request.method == 'POST'):
            form = addQuestionform(request.POST)
            if (form.is_valid()):
                ...
                pass=approved_questions(request, form)

                return redirect("login")
      
        context = {'form': form}
        return render(request, 'addQuestion.html', context)
shanksfk
  • 98
  • 7
  • Thank you for answer! But i get Error: approve_questions() missing 1 required positional argument: 'form' –  Dec 06 '22 at 03:30
  • did you add this line `pass=approved_questions(request, form)` into the `questions` view? you can see my answer I already stated that. – shanksfk Dec 06 '22 at 03:35
  • when I do that, pass=approved_questions is underlined in red and when I click on it, I get the following message: Statement expected, found Py:EQ –  Dec 06 '22 at 03:46
  • rearrange the views function so that `approved_questions` are defined first then only `questions`. if this is still not working you may have to use Javascript async to fetch data from the html – shanksfk Dec 06 '22 at 03:51