搜索

首页  >  问答  >  正文

如何将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粉596191963452 天前606

全部回复(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
  • 取消回复