All Projects → timmyomahony → Django Pagedown

timmyomahony / Django Pagedown

Licence: bsd-3-clause
A django app that allows the easy addition of Stack Overflow's "PageDown" markdown editor to a django form field, whether in a custom app or the Django Admin

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Django Pagedown

Django Markdown Editor
Awesome Django Markdown Editor, supported for Bootstrap & Semantic-UI
Stars: ✭ 423 (-15.4%)
Mutual labels:  markdown, django, markdown-editor
For Editor
for-editor - A markdown editor based on React
Stars: ✭ 358 (-28.4%)
Mutual labels:  markdown, markdown-editor
Awesome Django Admin
Curated List of Awesome Django Admin Panel Articles, Libraries/Packages, Books, Themes, Videos, Resources.
Stars: ✭ 356 (-28.8%)
Mutual labels:  django, django-admin
Django Object Actions
A Django app for easily adding object tools in the Django admin
Stars: ✭ 374 (-25.2%)
Mutual labels:  django, django-admin
Marcdown
👻 Lightweight realtime markdown viewer and editor - Simple, clean and beautiful https://liyasthomas.github.io/marcdown
Stars: ✭ 345 (-31%)
Mutual labels:  markdown, markdown-editor
Githuber Md
Markdown editor plugin for WordPress.
Stars: ✭ 353 (-29.4%)
Mutual labels:  markdown, markdown-editor
Django Cruds Adminlte
django-cruds is simple drop-in django app that creates CRUD for faster prototyping
Stars: ✭ 373 (-25.4%)
Mutual labels:  django, django-admin
Phodit
Phodal's markdown/ebook editor with MicroFrontend & Web Components
Stars: ✭ 301 (-39.8%)
Mutual labels:  markdown, markdown-editor
Justwrite
一款支持同步滑动预览的跨平台Markdown编辑器
Stars: ✭ 411 (-17.8%)
Mutual labels:  markdown, markdown-editor
Django Flat Theme
A flat theme for Django admin interface. Modern, fresh, simple.
Stars: ✭ 415 (-17%)
Mutual labels:  django, django-admin
Moeditor
(discontinued) Your all-purpose markdown editor.
Stars: ✭ 4,003 (+700.6%)
Mutual labels:  markdown, markdown-editor
Issues
Caret issues
Stars: ✭ 326 (-34.8%)
Mutual labels:  markdown, markdown-editor
Grav Plugin Admin
Grav Admin Plugin
Stars: ✭ 316 (-36.8%)
Mutual labels:  markdown, markdown-editor
Marky
A markdown editor built with Electron and React
Stars: ✭ 355 (-29%)
Mutual labels:  markdown, markdown-editor
Markdown Preview Enhanced
One of the 'BEST' markdown preview extensions for Atom editor!
Stars: ✭ 3,478 (+595.6%)
Mutual labels:  markdown, markdown-editor
Notes
✎ Distraction-free notes and writing
Stars: ✭ 363 (-27.4%)
Mutual labels:  markdown, markdown-editor
Codeexpander
A cross-platform cloud synchronization development tool for developers that includes input enhancement, code snippet management, and Markdown. (专为开发者开发的一个集输入增强、代码片段管理(支持 Markdown)为一体跨平台云同步的开发工具。)
Stars: ✭ 285 (-43%)
Mutual labels:  markdown, markdown-editor
Waliki
A wiki engine powered by Django and Git
Stars: ✭ 300 (-40%)
Mutual labels:  markdown, django
React Md Editor
A simple markdown editor with preview, implemented with React.js and TypeScript.
Stars: ✭ 374 (-25.2%)
Mutual labels:  markdown, markdown-editor
Django Nested Admin
Django admin classes that allow for nested inlines
Stars: ✭ 463 (-7.4%)
Mutual labels:  django, django-admin

Django Pagedown

Add Stack Overflow's "Pagedown" Markdown editor to your Django Admin or custom form.

Screenshot of Django Admin with Pagedown initialised

Requirements

Version >= 2.0.0 of django-pagedown requires Django 2.1.0 or above (previous versions should support Django all the way back to around 1.1).

Installation

  1. Get the code: pip install django-pagedown
  2. Add pagedown.apps.PagedownConfig to your INSTALLED_APPS
  3. Collect the static files: python manage.py collectstatic

Usage

The widget can be used both inside the django admin or independendly.

Inside the Django Admin:

If you want to use the pagedown editor in a django admin field, there are numerous possible approaches:

  • To use it in all TextField's in your admin form:

    from django.contrib import admin
    from django.db import models
    
    from pagedown.widgets import AdminPagedownWidget
    
    
    class AlbumAdmin(admin.ModelAdmin):
        formfield_overrides = {
            models.TextField: {'widget': AdminPagedownWidget },
        }
    
  • To only use it on particular fields, first create a form (in forms.py):

    from django import forms
    
    from pagedown.widgets import AdminPagedownWidget
    
    from music.models import Album
    
    class AlbumForm(forms.ModelForm):
        name = forms.CharField(widget=AdminPagedownWidget())
        description = forms.CharField(widget=AdminPagedownWidget())
    
        class Meta:
            model = Album
            fields = "__all__"
    

    and in your admin.py:

    from django.contrib import admin
    
    from forms import FooModelForm
    from models import FooModel
    
    @admin.register(FooModel)
    class FooModelAdmin(admin.ModelAdmin):
        form = FooModelForm
        fields = "__all__"
    

Outside the Django Admin:

To use the widget outside of the django admin, first create a form similar to the above but using the basic PagedownWidget:

from django import forms

from pagedown.widgets import PagedownWidget

from music.models import Album


class AlbumForm(forms.ModelForm):
    name = forms.CharField(widget=PagedownWidget())
    description = forms.CharField(widget=PagedownWidget())

    class Meta:
        model = Album
        fields = ["name", "description"]

Then define your urls/views:

from django.views.generic import FormView
from django.conf.urls import patterns, url

from music.forms import AlbumForm

urlpatterns = patterns('',
    url(r'^$', FormView.as_view(template_name="baz.html",
                                form_class=AlbumForm)),)

then create the template and load the javascipt and css required to create the editor:

<html>
    <head>
        {{ form.media }}
    </head>
    <body>
        <form ...>
            {{ form }}
        </form>
    </body>
</html>

Customizing the Widget

If you want to customize the widget, the easiest way is to simply extend it:

from pagedown.widgets import PagedownWidget


class MyNewWidget(PagedownWidget):
    template_name = '/custom/template.html'

    class Media:
        css = {
            'all': ('custom/stylesheets.css',)
        }
        js = ('custom/javascript.js',)

Rendering Markdown

contrib.markdown was deprecated in Django 1.5 meaning you can no longer use the markdown filter in your template by default.

@wkcd has a good example of how to overcome by installing django-markdown-deux:

{% extends 'base.html' %}
{% load markdown_deux_tags %}

...
<p>{{ entry.body|markdown }}</p>
...

Image Uploads

You can enable image uploads, allowing your users to upload new images to the server and have them automatically inserted into the Pagedown widget (instead of just adding image URLs):

Screenshot of Django Admin with image upload enabled

To do so:

  1. Make sure you have set a MEDIA_URL and MEDIA_ROOT so that uploads will be propertly saved
  2. Add PAGEDOWN_IMAGE_UPLOAD_ENABLED=True to your settings
  3. Include the pagedown paths in your urls.py so that the upload endpoint is available
 # ...
 urlpatterns = [
     path('', include('pagedown.urls')),
     # ...
 ]

This will add the URL /pagedown/image-upload/ endpoint to your project. You can see the default view that handles the upload here

The following options are available via your settings to tweak how the image upload works:

  • PAGEDOWN_IMAGE_UPLOAD_PATH can be used to change the path within your media root (default is pagedown-uploads)
  • PAGEDOWN_IMAGE_UPLOAD_EXTENSIONS can be used to limit the extensions allowed for upload (default is jpg, jpeg, png, webp)
  • PAGEDOWN_IMAGE_UPLOAD_UNIQUE can be used to ensure all uploads are stored in a uniquely named subfolder, e.g. f748e009-c3cb-40f3-abf2-d103ab0ad259/my-file.png (default is False)

Check out the pagedown_init.js script to see how the upload is being performed on the client side.

Example

You can see a fully-fledged example of the widget in django-pagedown-example

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].