neutronX / django-markdownx

Comprehensive Markdown plugin built for Django
https://neutronx.github.io/django-markdownx/
Other
863 stars 153 forks source link

Image path inside an app #104

Closed alaorneto closed 6 years ago

alaorneto commented 6 years ago

I'm following the tutorial to test markdownx, but I'm facing a problem.

My project is called "theproject", then I have my form inside an app, let's say "myapp".

I have set the following variables in my project's settings.py:

MEDIA_ROOT = BASE_DIR + '/media/'
# Markdownx configurations
MARKDOWNX_MEDIA_PATH = datetime.now().strftime('upload/%Y/%m/%d')

When I drag some jpeg to the editor, it gets upload to /theproject/media/upload/YYYY/MM/DD/.

But the GET request is being made to /myapp/upload/YYYY/MM/DD, so I get an 404 error and the image is not shown.

How can I solve this?

xenatisch commented 6 years ago

Apologies for the late response.

You solved it, or gave up, or still need help?

alaorneto commented 6 years ago

I gave up, actually.

jihoonerd commented 6 years ago

For your case it can be achieved as following:

settings.py

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/upload/'
MARKDOWNX_MEDIA_PATH = datetime.now().strftime('%Y/%m/%d')

urls.py (project level)

...
from django.conf.urls.static import static
from django.conf import settings

urlpatterns = [
   ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

As described in official django documents, it is not the best idea to serve static files like the way above. However, if your contents are not updated very frequently it should be fine.