相关疑难解决方法(0)

Django - 从POST请求获取值

我有以下django模板(http:// IP/admin/start /被分配给一个名为view的假想视图):

{% for source in sources %}
  <tr>
    <td>{{ source }}</td>

    <td>
    <form action="/admin/start/" method="post">
      {% csrf_token %}
      <input type="hidden" name="{{ source.title }}">
      <input type="submit" value="Start" class="btn btn-primary">
    </form>
    </td>

  </tr>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

sourcesobjects.all()视图中引用的Django模型.每当单击"开始"提交输入时,我希望"开始"视图{{ source.title}}在返回呈现页面之前使用函数中的数据.如何将信息(在本例中为隐藏输入)收集到Python变量中?

python django post

69
推荐指数
3
解决办法
17万
查看次数

Django request.GET

我似乎无法让这个例子打印出"你什么都没提交!".每次我提交一份空表格时都会说:

你提交了:你''

代替:

你什么都没提交!

我哪里做错了?

views.py

def search(request):
    if 'q' in request.GET:
        message = 'You submitted: %r' % request.GET['q']
    else:
        message = 'You submitted nothing!'

    return HttpResponse(message)
Run Code Online (Sandbox Code Playgroud)

模板:

<html>
    <head>
        <title> Search </title>
    </head>
    <body>
        <form action="/search/"  method="get" >
        <input type="text" name = "q">
        <input type="submit"value="Search"/>
        </form>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

django request

19
推荐指数
2
解决办法
9万
查看次数

在Django中访问post方法的表单数据

我想访问views.py 中的post 方法数据。我正在遵循将纯 html 用于表单而不是Django 表单类的过程。我在 Django 中尝试了MultiValueDictKeyError解决方案 但仍然无法正常工作。帮帮我

索引.html

<form action="{% url "Sample:print" %}" method="post">
    {% csrf_token %}
    <input type="text" placeholder="enter anything" id="TB_sample"/><br>
    <input type="submit" value="submit">
</form>
Run Code Online (Sandbox Code Playgroud)

视图.py

def print(request):
    value=request.POST['TB_sample']
    # value = request.REQUEST.get(request,'TB_sample')
    # value = request.POST.get('TB_sample','')
    print(value)
    return render(request , 'static/Sample/print.html',{"data":"I want to pass here 'Value'"})
Run Code Online (Sandbox Code Playgroud)

我尝试了所有注释类型。我仍然有很多错误。这些解决方案都不起作用。

python django

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

django ×3

python ×2

post ×1

request ×1