CARVIEW |
Select Language
HTTP/2 200
date: Tue, 22 Jul 2025 22:42:18 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"323d832faad9e32aee9a2f135896da83"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=pgFRH%2BEQykhVaRSPxFdplP4tx%2BF5ijnh06UBXgI9X7ILoO9USyiZGivvBg%2FP5eoyq%2BZzFSPjeMZuwp%2B7yPWMHI%2FI56OboHKy%2BPuxcFqxwgwZg1Lps2YDu%2F8GQIN%2FxiPiBpgleF7arKCD%2FKbduiqRr9EP3v4X%2FVnVicJPZx2ZyRWlbPXZy408rAmxFvMxJgAnkT0HRoIUV1KdXrvh2CFnToSa0R46x71SsvkuqcB7UPYdnWszVpBB%2B9J2wT9aCK5u%2FGppfIP0m0fSV%2FUGc0dkYw%3D%3D--e9YiMajfyfDr3CHL--HBjDEnJJzTwvfndNls%2BwUg%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.2014223680.1753224137; Path=/; Domain=github.com; Expires=Wed, 22 Jul 2026 22:42:17 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Wed, 22 Jul 2026 22:42:17 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: DF62:33F9F4:194E57:225085:688013C9
Home · agusmakmun/django-markdown-editor Wiki · GitHub
Skip to content
Navigation Menu
{{ message }}
-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Home
agusmakmun edited this page Nov 16, 2021
·
11 revisions
If you want to save images uploaded to your storage, MARTOR also provides a way to handle this by allowing you to use a custom uploader. The scripts below show how you could do this:
1. settings.py
# Global martor settings
# Input: string boolean, `true/false`
MARTOR_ENABLE_CONFIGS = {
....
'imgur': 'true', # to enable/disable imgur uploader/custom uploader.
'mention': 'true', # to enable/disable mention
'jquery': 'true', # to include/revoke jquery (require for admin default django)
}
# Upload to locale storage
import time
MARTOR_UPLOAD_PATH = 'images/uploads/{}'.format(time.strftime("%Y/%m/%d/"))
MARTOR_UPLOAD_URL = '/api/uploader/' # change to local uploader
# Maximum Upload Image
# 2.5MB - 2621440
# 5MB - 5242880
# 10MB - 10485760
# 20MB - 20971520
# 50MB - 5242880
# 100MB 104857600
# 250MB - 214958080
# 500MB - 429916160
MAX_IMAGE_UPLOAD_SIZE = 5242880 # 5MB
# Media Path
MEDIA_URL = '/media/'
MEDIA_ROOT = '/path/to/yourenv/yourproject/media'
2. views.py
import os
import json
import uuid
from django.conf import settings
from django.http import HttpResponse
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.decorators import login_required
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
from martor.utils import LazyEncoder
@login_required
def markdown_uploader(request):
"""
Makdown image upload for locale storage
and represent as json to markdown editor.
"""
if request.method == 'POST' and request.is_ajax():
if 'markdown-image-upload' in request.FILES:
image = request.FILES['markdown-image-upload']
image_types = [
'image/png', 'image/jpg',
'image/jpeg', 'image/pjpeg', 'image/gif'
]
if image.content_type not in image_types:
data = json.dumps({
'status': 405,
'error': _('Bad image format.')
}, cls=LazyEncoder)
return HttpResponse(
data, content_type='application/json', status=405)
if image._size > settings.MAX_IMAGE_UPLOAD_SIZE:
to_MB = settings.MAX_IMAGE_UPLOAD_SIZE / (1024 * 1024)
data = json.dumps({
'status': 405,
'error': _('Maximum image file is %(size)s MB.') % {'size': to_MB}
}, cls=LazyEncoder)
return HttpResponse(
data, content_type='application/json', status=405)
img_uuid = "{0}-{1}".format(uuid.uuid4().hex[:10], image.name.replace(' ', '-'))
tmp_file = os.path.join(settings.MARTOR_UPLOAD_PATH, img_uuid)
def_path = default_storage.save(tmp_file, ContentFile(image.read()))
img_url = os.path.join(settings.MEDIA_URL, def_path)
data = json.dumps({
'status': 200,
'link': img_url,
'name': image.name
})
return HttpResponse(data, content_type='application/json')
return HttpResponse(_('Invalid request!'))
return HttpResponse(_('Invalid request!'))
3. urls.py
from yourapp.views import markdown_uploader
urlpatterns = [
....
url(
r'^api/uploader/$',
markdown_uploader, name='markdown_uploader_page'
),
]
To support Django 2 for the urls.py script in part 3 it would be good to also add:
from yourapp.views import markdown_uploader
urlpatterns = [
....
path(
'api/uploader/', markdown_uploader, name='markdown_uploader_page'
),
]
I hope this is useful, if you have any questions or anything let me know 👍
Clone this wiki locally
You can’t perform that action at this time.