Coder Social home page Coder Social logo

tjj021 / django-quill-editor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from leehanyeong/django-quill-editor

0.0 1.0 0.0 1.67 MB

django-quill-editor makes Quill.js easy to use on Django Forms and admin sites

Home Page: https://django-quill-editor.readthedocs.io

License: MIT License

Python 84.93% CSS 0.52% JavaScript 4.33% HTML 10.22%

django-quill-editor's Introduction

django-quill-editor

PyPI version Documentation Status

django-quill-editor makes Quill.js easy to use on Django Forms and admin sites

  • No configuration required for static files!
  • The entire code for inserting WYSIWYG editor is less than 30 lines
  • It can be used in both admin and Django views

django-quill-editor

Setup

  • Install django-quill-editor to your Python environment

    pip install django-quill-editor
  • Add django_quill to INSTALLED_APPS in settings.py

    # settings.py
    INSTALLED_APPS = [
        'django.contrib.admin',
        ...
        'django_quill',
    ]

Run Sample project

Repo: django-quill-editor-sample

# Clone repo
git clone https://github.com/LeeHanYeong/django-quill-editor-sample
cd django-quill-editor-sample

# Create virtualenv (I used pyenv, but you can use other methods)
pyenv virtualenv 3.7.5 django-quill
pyenv local django-quill

# Install Python packages
pip install -r requirements.txt
python app/manage.py runserver

Documentation

Documentation for django-quill-editor is located at https://django-quill-editor.readthedocs.io/

Change toolbar configs

Add QUILL_CONFIGS to the settings.py

QUILL_CONFIGS = {
    'default':{
        'theme': 'snow',
        'modules': {
            'syntax': True,
            'toolbar': [
                [
                    {'font': []},
                    {'header': []},
                    {'align': []},
                    'bold', 'italic', 'underline', 'strike', 'blockquote',
                    {'color': []},
                    {'background': []},
                ],
                ['code-block', 'link'],
                ['clean'],
            ]
        }
    }
}

Usage

Add QuillField to the Model class you want to use

# models.py
from django.db import models
from django_quill.fields import QuillField

class QuillPost(models.Model):
    content = QuillField()

1. Django admin

Just register the Model in admin.py of the app.

from django.contrib import admin
from .models import QuillPost

@admin.register(QuillPost)
class QuillPostAdmin(admin.ModelAdmin):
    pass

admin-sample

2. Form

  • Add QuillFormField to the Form class you want to use

  • There are two ways to add CSS and JS files to a template.

    • If there is a Form with QuillField added, add {{ form.media }} to the <head> tag.

      <head>
          {{ form.media }}
      </head>
    • Or, import CSS and JS files directly using {% include %} template tags.

      <head>
          <!-- django-quill-editor Media -->
          {% include 'django_quill/media.html' %}
      </head>
# forms.py
from django import forms
from django_quill.forms import QuillFormField

class QuillFieldForm(forms.Form):
    content = QuillFormField()
# views.py
from django.shortcuts import render
from .forms import QuillFieldForm

def form(request):
    return render(request, 'form.html', {'form': QuillFieldForm()})
<!-- Template -->
<form action="" method="POST">{% csrf_token %}
    {{ form.content }}
</form>

3. ModelForm

Just define and use ModelForm of Model class

# forms.py
from django import forms
from .models import QuillPost

class QuillPostForm(forms.ModelForm):
    class Meta:
        model = QuillPost
        fields = (
            'content',
        )
# views.py
from django.shortcuts import render
from .forms import QuillPostForm

def model_form(request):
    return render(request, 'model_form.html', {'form': QuillPostForm()})
<!-- Template -->
<form action="" method="POST">{% csrf_token %}
    {{ form.content }}
</form>

Form, ModelForm's Output:

form-sample

Contributing

As an open source project, we welcome contributions. The code lives on GitHub

Distribution (for owners)

PyPI Release

poetry install  # Install PyPI distribution packages
python deploy.py

Sphinx docs

brew install sphinx-doc  # macOS

Local

cd docs
make html
# ...
# The HTML pages are in _build/html.

cd _build/html
python -m http.server 3001

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.