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.0.tar.gz
(23.3 kB
view hashes)
Built Distribution
Close
Hashes for django_ktag-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9071756a8f631cf20c186c56f67386d989630424b307c4a0ffd3be8098b5ca84 |
|
MD5 | a07a55028a122413fd7d6edbdf958d2d |
|
BLAKE2b-256 | 4987e18d8356f2aa1e1d054682fd76f4db82762e74b6b95e5a0c5c60d9a4a004 |