Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media URL wrong in Django 1.8.2 #198

Closed
xros opened this issue Jun 11, 2015 · 7 comments
Closed

Media URL wrong in Django 1.8.2 #198

xros opened this issue Jun 11, 2015 · 7 comments

Comments

@xros
Copy link

xros commented Jun 11, 2015

The django-ckeditor did successfully upload the media and stored the image under a folder, say, ./media/uploads/

Every time after I successfully upload the picture to the server using django-ckeditor, the django-ckeditor would request a URL which looks like this

uploads/2015/06/11/app_software_360.jpg

And that indicates the browser is requesting to

http://localhost:8000/somewhere/someplace/uploads/2015/06/11/app_software_360.jpg

but not http://localhost:8000/media/uploads/2015/06/11/app_software_360.jpg This is the actually right URL location, but django-ckeditor just can not find it out. I guess this has something to do with the settings.py

You just can not fetch the right media URL, how to fix this?

@riklaunim
Copy link
Contributor

what's your MEDIA_URL setting?

@xros
Copy link
Author

xros commented Jun 11, 2015

Here's some scope of settings.py

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(BASE_DIR,  'templates'),


        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'django.template.context_processors.media',
            ],
        },
    },
]

MEDIA_ROOT = os.path.join(BASE_DIR, "media")



CKEDITOR_UPLOAD_PATH = 'uploads/'
#CKEDITOR_UPLOAD_PATH = ''

CKEDITOR_JQUERY_URL = '//code.jquery.com/jquery-1.11.1.min.js'

CKEDITOR_CONFIGS = {
    'default': {
        #'toolbar': 'Basic',
        'toolbar': 'Full',
    },
}

CKEDITOR_IMAGE_BACKEND = 'pillow'

I haven't set the MEDIA_URL in the settings.py yet.

and in the urls.py of the project,

if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_LOCAL)

    urlpatterns += patterns('',
        (r'^media/(?P<path>.*)$', 'django.views.static.serve', {
        'document_root': settings.MEDIA_ROOT}))

@xros
Copy link
Author

xros commented Jun 11, 2015

Problem solved!
by adding these to settings.py

MEDIA_ROOT = os.path.join(BASE_DIR, "media")
MEDIA_URL = '/media/'

The MEDIA_URL must be included in the settings.py

@xros
Copy link
Author

xros commented Jun 11, 2015

But I think this should be included in the README.md if any.
Tell people that , they need to set up MEDIA_ROOT, MEDIA_URL first for a new django project.

@riklaunim
Copy link
Contributor

No media files will link correctly without MEDIA_URL.

@ayagebreel
Copy link

but i have an error : "patterns" is not defined

@riklaunim
Copy link
Contributor

Did you looked at the traceback?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants