Django Dropdown populate from mongodb databases

  Django

Email

Django Dropdown populate from mongodbdatabases

view.py


def adminsubmenu(request):
mainmenu_name= Mainmenu.objects.all()
mainmenuname = request.GET.get('mainmenu_name')
return render(request, 'admin_super/home/submainmenu.html',{'mainmenu_name':mainmenu_name})
html page
 
<formclass="forms-sample"action=''method="POST">
<divclass="form-group">
<labelfor="exampleFormControlSelect2">Select Main Menu</label>
<selectclass="form-control"id="exampleFormControlSelect2">
{% for name in mainmenu_name %}
<optionvalue="{{ name.id }}">{{ name.mainmenu_name }}</option>
{% endfor %}
</select>
</div>
 
<divclass="form-group">
<labelfor="exampleInputCity1">sub Main menu</label>
<inputtype="text"class="form-control"id="exampleInputCity1"placeholder="Location">
</div>
{% csrf_token %}
 
<buttontype="submit"class="btn btn-success mr-2">Submit</button>
</form>
 
Spread the Code

Leave a Reply

avatar

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
Notify of