django tag input field
Project description
django tag input field
Install
pip install django-ktag
Requirements
python 3+
django 2+
Quick Start
The settings
Add ‘ktag’ application to the INSTALLED_APPS
INSTALLED_APPS = [
...
'ktag',
]
Make sure APP_DIRS is True in TEMPLATES
TEMPLATES = [
...
'APP_DIRS': True,
...
]
The form class
Building a form in Django like this:
from django import forms
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-1.0.3.tar.gz
(23.4 kB
view details)
File details
Details for the file django-ktag-1.0.3.tar.gz
.
File metadata
- Download URL: django-ktag-1.0.3.tar.gz
- Upload date:
- Size: 23.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb057f995bbf793b68669bdb01729716653ac39f0447e936d875ca65bf186d94 |
|
MD5 | 45fe23b4cf05d19b8cc63bce34ae6566 |
|
BLAKE2b-256 | ae37637b232365f052f7a8fbf20f7e06803c2552dbfdee56b6c603849d9acfdf |