Django - taking values from POST request

前端 未结 3 1123
旧巷少年郎
旧巷少年郎 2020-11-30 23:57

I have the following django template (http://IP/admin/start/ is assigned to a hypothetical view called view):

{% for source in sources %}
  
    &l         


        
相关标签:
3条回答
  • 2020-12-01 00:12

    If you need to do something on the front end you can respond to the onsubmit event of your form. If you are just posting to admin/start you can access post variables in your view through the request object. request.POST which is a dictionary of post variables

    0 讨论(0)
  • 2020-12-01 00:24

    Read about request objects that your views receive: https://docs.djangoproject.com/en/dev/ref/request-response/#httprequest-objects

    Also your hidden field needs a reliable name and then a value:

    <input type="hidden" name="title" value="{{ source.title }}">
    

    Then in a view:

    request.POST.get("title", "")
    
    0 讨论(0)
  • 2020-12-01 00:37

    For django forms you can do this;

    form = UserLoginForm(data=request.POST) #getting the whole data from the user.
    user = form.save() #saving the details obtained from the user.
    username = user.cleaned_data.get("username") #where "username" in parenthesis is the name of the Charfield (the variale name i.e, username = forms.Charfield(max_length=64))
    
    0 讨论(0)
提交回复
热议问题