• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

django-tagify2: django tag input field, use tagify

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

django-tagify2

开源软件地址:

https://gitee.com/gojuukaze/django-ktag

开源软件介绍:


django-tagify2

GitHub versionLicense: GPL v3

django tag input field using tagify

alt tag

Requirements

  • python3+
  • django 2.0+ (maybe 1.x)

Documentation

Installation

  • download
pip install django-tagify2orpip install --index-url https://pypi.org/simple/ django-tagify2 
  • Add 'tagify' application to the INSTALLED_APPS
INSTALLED_APPS = [    ...    'tagify',]
  • Make sure APP_DIRS is True in TEMPLATES
TEMPLATES = [    ...    'APP_DIRS': True,                ...]

Usage

Quick Start

The form class

Building a form in Django like this:

from django import formsfrom tagify.fields import TagFieldclass TagForm(forms.Form):    languages = TagField(label='languages', place_holder='add a language', delimiters=' ',                         data_list=['Python', 'Java', 'PHP', 'Golang', 'JavaScript'], initial='Python Golang')# or def random_number():    return [random.randint(10, 19), random.randint(10, 19), random.randint(10, 19), random.randint(10, 19), ]class NumberForm(forms.Form):    number = TagField(label='number', place_holder='add a number', delimiters=' ',                      data_list=random_number)# or class TagForm(forms.Form):    languages = TagField(label='languages', place_holder='add a language', delimiters=' ', )    def __init__(self, *args, **kwargs):        super().__init__(*args, **kwargs)        self.fields['languages'].set_tag_args('data_list', get_languages())

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 HttpResponsefrom django.shortcuts import renderfrom example.forms import TagFormdef index(request):    if request.method == 'POST':        form = TagForm(request.POST)        if form.is_valid():            return HttpResponse(str(form.cleaned_data['languages']))    else:        form = TagForm()    return render(request, 'index.html', {'form': form})

The template

The simplest example is:

<head>    {{ form.media }}</head><body>  <form action="" method="post">      {% csrf_token %}      {{ form }}      <br>      <input type="submit" value="OK">  </form></body>

Using With Model

from django.db import modelsfrom tagify.models import TagFieldclass People(models.Model):    name = models.CharField(max_length=30)    languages = TagField(verbose_name='languages')

Field Arguments

NameTypeDefaultInfo
place_holderstring""placeholder
delimitersstring","split tags by any of these delimiters. Example: Space or Coma - ", "
data_listlist/function[]an array of tags which they are allowed
black_listlist[]an array of tags which aren't allowed
max_tagsintNonemax number of tags
suggestions_charsint1minimum characters to input which shows the sugegstions list
patternstring""Validate input by RegEx pattern. Ex: "[1-9]"

Example

Run example

git clone [email protected]:gojuukaze/django-tagify2.git  cd django-tagify2pip install djangopython manage.py makemigrations example python manage.py createsuperuserpython manage.py migrate   python manage.py runserver # open# http://127.0.0.1:8000# http://127.0.0.1:8000/number# http://127.0.0.1:8000/admin/example/people/

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap