{"id":13502679,"url":"https://github.com/timmyomahony/django-pagedown","last_synced_at":"2025-04-08T09:06:39.729Z","repository":{"id":3064639,"uuid":"4087186","full_name":"timmyomahony/django-pagedown","owner":"timmyomahony","description":"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","archived":false,"fork":false,"pushed_at":"2021-07-30T19:54:48.000Z","size":515,"stargazers_count":576,"open_issues_count":4,"forks_count":91,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-04-01T07:52:04.376Z","etag":null,"topics":["django","django-admin","django-pagedown","django-project","markdown","markdown-editor","pagedown"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"mdlayher/obd","license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/timmyomahony.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-04-20T14:06:17.000Z","updated_at":"2025-03-18T00:39:10.000Z","dependencies_parsed_at":"2022-08-20T08:20:50.125Z","dependency_job_id":null,"html_url":"https://github.com/timmyomahony/django-pagedown","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timmyomahony%2Fdjango-pagedown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timmyomahony%2Fdjango-pagedown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timmyomahony%2Fdjango-pagedown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timmyomahony%2Fdjango-pagedown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timmyomahony","download_url":"https://codeload.github.com/timmyomahony/django-pagedown/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247809964,"owners_count":20999816,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","django-admin","django-pagedown","django-project","markdown","markdown-editor","pagedown"],"created_at":"2024-07-31T22:02:22.003Z","updated_at":"2025-04-08T09:06:39.691Z","avatar_url":"https://github.com/timmyomahony.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"Django Pagedown\n===============\n\nAdd [Stack Overflow\u0026#39;s \u0026quot;Pagedown\u0026quot; Markdown editor](https://github.com/StackExchange/pagedown/) to your Django Admin or custom form.\n\n![Screenshot of Django Admin with Pagedown initialised](https://github.com/timmyomahony/django-pagedown/blob/master/screenshot.png?raw=true \"A screenshot of Pagedown in Django's admin\")\n\n## Requirements\n\nVersion \u003e= 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).\n\n## Installation\n\n1. Get the code: `pip install django-pagedown`\n2. Add `pagedown.apps.PagedownConfig` to your `INSTALLED_APPS` in `settings.py`\n3. [Configure and collect](https://docs.djangoproject.com/en/dev/howto/static-files/#configuring-static-files) the static files: `python manage.py collectstatic`\n\n## Usage\n\nThe widget can be used both inside the django admin or independendly. \n\n### Inside the Django Admin:\n\nIf you want to use the pagedown editor in a django admin field, there are numerous possible approaches:\n\n- To use it in **all** `TextField`'s in your admin form:\n\n    ```python\n    from django.contrib import admin\n    from django.db import models\n\n    from pagedown.widgets import AdminPagedownWidget\n\n\n    class AlbumAdmin(admin.ModelAdmin):\n        formfield_overrides = {\n            models.TextField: {'widget': AdminPagedownWidget },\n        }\n    ```\n- To only use it on **particular fields**, first create a form (in `forms.py`):\n\n    ```python\n    from django import forms\n\n    from pagedown.widgets import AdminPagedownWidget\n\n    from music.models import Album\n\n    class AlbumForm(forms.ModelForm):\n        name = forms.CharField(widget=AdminPagedownWidget())\n        description = forms.CharField(widget=AdminPagedownWidget())\n\n        class Meta:\n            model = Album\n            fields = \"__all__\"\n    ```\n\n    and in your `admin.py`:\n\n    ```python\n    from django.contrib import admin\n\n    from forms import FooModelForm\n    from models import FooModel\n\n    @admin.register(FooModel)\n    class FooModelAdmin(admin.ModelAdmin):\n        form = FooModelForm\n        fields = \"__all__\"\n    ```\n\n### Outside the Django Admin:\n\nTo use the widget outside of the django admin, first create a form similar to the above but using the basic `PagedownWidget`:\n\n```python\nfrom django import forms\n\nfrom pagedown.widgets import PagedownWidget\n\nfrom music.models import Album\n\n\nclass AlbumForm(forms.ModelForm):\n    name = forms.CharField(widget=PagedownWidget())\n    description = forms.CharField(widget=PagedownWidget())\n\n    class Meta:\n        model = Album\n        fields = [\"name\", \"description\"]\n```\n\nThen define your urls/views:\n\n```py\nfrom django.views.generic import FormView\nfrom django.conf.urls import patterns, url\n\nfrom music.forms import AlbumForm\n\nurlpatterns = patterns('',\n    url(r'^$', FormView.as_view(template_name=\"baz.html\",\n                                form_class=AlbumForm)),)\n```\n\nthen create the template and load the javascipt and css required to create the editor:\n\n```html\n\u003chtml\u003e\n    \u003chead\u003e\n        {{ form.media }}\n    \u003c/head\u003e\n    \u003cbody\u003e\n        \u003cform ...\u003e\n            {{ form }}\n        \u003c/form\u003e\n    \u003c/body\u003e\n\u003c/html\u003e\n```\n\n## Customizing the Widget\n\nIf you want to customize the widget, the easiest way is to simply extend it:\n\n```py\nfrom pagedown.widgets import PagedownWidget\n\n\nclass MyNewWidget(PagedownWidget):\n    template_name = '/custom/template.html'\n\n    class Media:\n        css = {\n            'all': ('custom/stylesheets.css',)\n        }\n        js = ('custom/javascript.js',)\n```\n\n\n## Rendering Markdown\n\n`contrib.markdown` was [deprecated in Django 1.5](https://code.djangoproject.com/ticket/18054) meaning you can no longer use the `markdown` filter in your template by default.\n\n[@wkcd has a good example](https://github.com/timmyomahony/django-pagedown/issues/18#issuecomment-37535535) of how to overcome by installing `django-markdown-deux`:\n\n```py\n{% extends 'base.html' %}\n{% load markdown_deux_tags %}\n\n...\n\u003cp\u003e{{ entry.body|markdown }}\u003c/p\u003e\n...\n```\n\n## Image Uploads\n\nYou 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):\n\n![Screenshot of Django Admin with image upload enabled](https://github.com/timmyomahony/django-pagedown/blob/develop/image-upload.png?raw=true \"Screenshot of Django Admin with image upload enabled\")\n\nTo do so:\n\n1. Make sure you have set a `MEDIA_URL` and `MEDIA_ROOT` so that uploads will be propertly saved\n2. Add `PAGEDOWN_IMAGE_UPLOAD_ENABLED=True` to your settings\n3. Include the pagedown paths in your `urls.py` so that the upload endpoint is available\n\n```py\n # ...\n urlpatterns = [\n     path('', include('pagedown.urls')),\n     # ...\n ]\n```\n\nThis will add the URL `/pagedown/image-upload/` endpoint to your project. You can [see the default view that handles the upload here](https://github.com/timmyomahony/django-pagedown/blob/develop/pagedown/views.py)\n\nThe following options are available via your settings to tweak how the image upload works:\n\n- `PAGEDOWN_IMAGE_UPLOAD_PATH` can be used to change the path within your media root (default is `pagedown-uploads`)\n- `PAGEDOWN_IMAGE_UPLOAD_EXTENSIONS` can be used to limit the extensions allowed for upload (default is `jpg`, `jpeg`, `png`, `webp`)\n- `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`)\n\nCheck out the `pagedown_init.js` script to [see how the upload is being performed on the client side](https://github.com/timmyomahony/django-pagedown/blob/develop/pagedown/static/pagedown_init.js).\n\n## Example\n\nYou can see a fully-fledged example of the widget in [`django-pagedown-example`](https://github.com/timmyomahony/django-pagedown-example)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimmyomahony%2Fdjango-pagedown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimmyomahony%2Fdjango-pagedown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimmyomahony%2Fdjango-pagedown/lists"}