首頁  >  問答  >  主體

如何將HTML內容傳送到另一個HTML頁面

<p>我想在一個html頁面上填寫一個表單,然後將填寫好的表單發送到另一個html頁面上進行檢查並儲存。我只是不知道如何將數據從一個html發送到另一個html。我請求你的幫助。謝謝</p> <pre class="brush:php;toolbar:false;">question.html 這是表單 {% extends 'dependencies.html' %} {% block content %} <div class="jumbotron container row"> <div class="col-md-6"> <h1>加問題</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 %}</pre> <pre class="brush:php;toolbar:false;">approve_questions.html 我想在這裡獲取question.html的內容 目前為空</pre> <pre class="brush:php;toolbar:false;">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")</pre>
P粉596191963P粉596191963432 天前576

全部回覆(1)我來回復

  • P粉776412597

    P粉7764125972023-09-06 10:58:01

    如果我正確理解了你的問題。

    你可以透過將表單變數傳遞給approved_questions視圖來實現。同樣

    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)

    回覆
    0
  • 取消回覆