django tag input field
Project description
django tag input field
Install
pip install django-ktag
Requirements
python 3+
django 2+
Quick Start
The form class
Our starting point for it in Django is this:
from ktag.fields import TagField
class TagForm(forms.Form):
fruits = TagField(label='fruits', place_holder='write your fruits', delimiters=' ',
data_list=['apple', 'banana', 'watermelon', 'orange'], initial='grape coconut')
The view
To handle the form we need to instantiate it in the view for the URL where we want it to be published:
from django.http import HttpResponse
from django.shortcuts import render
from example.forms import TagForm
def index(request):
if request.method == 'POST':
form = TagForm(request.POST)
if form.is_valid():
print(form.cleaned_data['fruits'])
return HttpResponse(str(form.cleaned_data['fruits']))
else:
form = TagForm()
return render(request, 'index.html', {'form': form})
The template
The simplest example is:
<form action="" method="post">
{% csrf_token %}
{{ form }}
<br>
<input type="submit" value="OK" style="font-size: larger">
</form>
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django-ktag-0.0.7.tar.gz
(23.1 kB
view hashes)
Built Distribution
Close
Hashes for django_ktag-0.0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecb1374ae6d5f7666c11977fcc1aa78eb64cf979c04b17754439ecef8d351aa1 |
|
MD5 | f90b7fe141dac36d8f0c53cd18e17751 |
|
BLAKE2b-256 | afabd872ea4502819a36a175fdded9bfb35c6a9bff8055444b1c3173f3e4cc04 |