Skip to main content

django tag input field

Project description

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>

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 hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page