Skip to main content

django tag input field

Home | Documentation

https://github.com/gojuukaze/django-ktag/blob/master/demo.gif?raw=true

Install

pip install django-ktag

Requirements

  • python 3+

  • django 2+

Quick Start

  • The settings

  1. Add ‘ktag’ application to the INSTALLED_APPS

INSTALLED_APPS = [
...
'ktag',
]
  1. 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>

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)

Uploaded Source

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

Hashes for django-ktag-1.0.3.tar.gz
Algorithm Hash digest
SHA256 eb057f995bbf793b68669bdb01729716653ac39f0447e936d875ca65bf186d94
MD5 45fe23b4cf05d19b8cc63bce34ae6566
BLAKE2b-256 ae37637b232365f052f7a8fbf20f7e06803c2552dbfdee56b6c603849d9acfdf

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.3 This release

1 file

1.0.2

1 file

1.0.1

1 file

1.0.0

2 files

0.0.7

2 files

0.0.6

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page