【问题标题】:HTML input label to python fileHTML输入标签到python文件
【发布时间】:2021-12-31 15:16:57
【问题描述】:

如何从 Html 输入标签中获取输入并在 python 文件中使用它而无需创建本地主机?我不需要保存输入,只需在 python 中运行即可。

【问题讨论】:

    标签: python html css python-3.x input


    【解决方案1】:
    def create_post(request):
        if request.method == 'POST':
            post_text = request.POST.get('the_post')
            response_data = {}
    
            post = Post(text=post_text, author=request.user)
            post.save()
    
            response_data['result'] = 'Create post successful!'
            response_data['postpk'] = post.pk
            response_data['text'] = post.text
            response_data['created'] = post.created.strftime('%B %d, %Y %I:%M %p')
            response_data['author'] = post.author.username
    
            return HttpResponse(
                json.dumps(response_data),
                content_type="application/json"
            )
        else:
            return HttpResponse(
                json.dumps({"nothing to see": "this isn't happening"}),
                content_type="application/json"
            )
    

    【讨论】:

    • {% csrf_token %}
      {{ form.text }}
    • 您的解决方案不起作用
    猜你喜欢
    • 2020-08-13
    • 1970-01-01
    • 2014-05-29
    • 2012-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多