How to populate html input in Django framework without using a any of Django form?

wernhervb

I'm implementing an HTML table that is populated with information as the page is rendered. I cannot use a form here but still, I need to embed some common input controls to certain s in that HTML table (selection boxes).

So I think the data itself can be passed to the template as the page is being rendered but do I need to use javascript to fill the controls? I think I cannot use anything related to forms here.

I have implemented a javascript ajax code to get the data when the table is filled by a user. That is working perfectly. But the user does not fill everything on that table but there must be some selections done before the data can be submitted. That data is read from the database, delivered to the HTML table for the user to make a selection.

But I have never used HTML inputs other than in Django forms.

Or is there a better solution to achieve this?

Edit: As the code that is given here as an answer is used the dropdown content of the selection control, it contains two classes as attributes: dropdown-content and select-dropdown. I changed the z-index in order to bring the dropdown box to the top. It did open but the container did hide the dropdown items inside it. So I made a test and by setting z-index to be large enough and the dropdown content came front. I have not used z-index before so please forgive me if I have done something funny here.

.dropdown-content {
     z-index: 33;
     position: relative;
}
.select-dropdown {
     z-index: 32;
     position: relative;
}
ming

if your data form model, you can use return data to html, like this:

views.py

def articleCreate(request):
    categrays = Categray.objects.all()
    context = {'categrays':categrays}
    return render(request, 'article/articleCreate.html', context)

and use {% for %} add your data to html.

<div class="categray">
  <label>Categray:</label><br>
  <select name=categray>
  {% for categray in categrays %}
    <option value={{categray.id}}>{{ categray.name }}</option>
  {% endfor %}
  </select>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to extract Django Form errors message without the HTML tags

how to create a autocomplete input field in a form using Django

Django : How to import a data from csv to database without using form?

Pre-populate HTML form table from database using Django

display any value from django views to html form input

How to implement pagination in a Django and React app without using the REST framework?

In Django, how to extract ID attribute from html Input tag, WITHOUT using django forms

How can I populate a manytomanyfield , using view, without django pre-built forms?

How can I populate an HTML table created by Django using javascript?

in django how to add data from html table without using form.py

Django use of form input without calling form

How to render some html using django form

Writing webapps in python without Django or any framework

Django How to pre-populate a form field with a argument form context

Django - how to get file input without using django form and attach the file to email

django-contact-form how to use the form inside any template, without a new url?

How to send image file without saving in database using django framework

How to make HTML form input fields responsive without using Bootstrap

Using Django framework only with admin backend without any apps

How to pre-populate form with data received from a previous HTML form submission in Django?

Django filter a ModelChoiceField queryset using the URL to populate a form

Populate dropdown in template from model choices using Django Rest Framework

In Django how to populate a form dropdown list form a column in a database

Django html form: how to only populate field value if it exists?

How to insert raw html into form when creating a page using django

How to redirect any website by clicking an image in html where framework is Django?

How to extract data from an html form using django?

How to keep html form data after submission using django?

django: How do i save form in django without the django forms?