Home > OS >  Django: If form doesn't have information set value to
Django: If form doesn't have information set value to

Time:04-05

If value in interval is not selected, i would like to use default one ( 1d )

    # if  i got post request
    if request.method == "POST":
        #  check if interval is choosen in form 
        if 'interval' in request.POST:
            interval= request.POST["interval"]
        else:
            interval = "1d"
        if "ticker" in request.POST:
            ticker= request.POST["ticker"]

enter image description here

the value of intervals is not check properly if is there enter image description here

CodePudding user response:

You set this default value in frontend. In your html:

<option selected="selected">
1d
</option>

I would argue that it is the better option.

You can of course check for empty string in the interval keyword

if request.POST["interval"] == "":
    interval = "1d"
  • Related