Comments (2)
Maybe try this. I did not test this but maybe it can help someone.
-
Install the python-flickrapi library by running
pip install flickrapi
in your terminal. -
In your Django project's settings.py file, add the following settings:
FLICKR_API_KEY = 'your_api_key_here'
FLICKR_API_SECRET = 'your_api_secret_here'
- In your Django project's urls.py file, add a URL pattern to handle the image upload:
from django.conf.urls import url
from markdownx import urls as markdownx
urlpatterns = [
# your other URL patterns here
url(r'^markdownx/flickr/$', 'your_app.views.flickr_upload', name='markdownx_flickr_upload'),
url(r'^markdownx/', include(markdownx)),
]
- In your Django app's views.py file, define a view to handle the image upload:
from django.http import HttpResponse
from flickrapi import FlickrAPI
from markdownx.utils import markdownify
def flickr_upload(request):
if request.method == 'POST':
# get the image data from the request
image_data = request.FILES['image']
# authenticate with Flickr
flickr = FlickrAPI(settings.FLICKR_API_KEY, settings.FLICKR_API_SECRET, format='etree')
(token, frob) = flickr.get_token_part_one(perms='write')
if not token:
raise Exception
- Redirect the user to Flickr's authentication page to authorize your app to upload images:
auth_url = flickr.auth_url(perms='write')
return HttpResponseRedirect(auth_url)
- After the user has authorized your app, retrieve the access token and secret:
flickr.get_token_part_two((token, frob))
access_token = flickr.token_cache.token.token
access_secret = flickr.token_cache.token.token_secret
- Upload the image to Flickr using the access token and secret:
response = flickr.upload(filename=image_data.name, fileobj=image_data, title='My Image', description='Uploaded with django-markdown-editor', auth_token=access_token, auth_secret=access_secret)
photo_id = response.find('photoid').text
- Finally, return the URL of the uploaded image to the markdown editor:
image_url = flickr.photos_getSizes(photo_id=photo_id)[0].find('source').attrib['url']
return HttpResponse(markdownify('![My Image]({})'.format(image_url)))
from django-markdown-editor.
Sounds like a great idea @SkippyHo. Can you submit a pull request?
from django-markdown-editor.
Related Issues (20)
- incompatibility with Python versions below 3.9 HOT 7
- After version 1.6.26 the setting MARTOR_UPLOAD_URL is ignored HOT 6
- The editor does not work when setting a Content Security Policy HOT 1
- Loosen restriction on importlib-metadata HOT 4
- Emoji url is done HOT 1
- class tag doesn't render correctly HOT 2
- toolbar nav style issue HOT 1
- Error with markdownify HOT 1
- Adding a new instance in an admin inline results in Uncaught TypeError HOT 1
- Losing text when (semi)colons follow links. HOT 2
- preview is not displaying correctly for “ordered” and “unordered” list items. HOT 1
- 📣 Call for Contributors: Help Needed to Maintain and Enhance django-markdown-editor! HOT 4
- Enable specifying the size of an image HOT 1
- Django 5 & Python 3.12 support HOT 2
- Updating Editor Content with Javascript HOT 1
- Django 4.2.11 support HOT 2
- Copy/Paste clipboard images HOT 1
- Dynamic MARTOR_UPLOAD_URL HOT 1
- Improve documentation for using html HOT 2
- Stop tagging Django with a less than version. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-markdown-editor.