django-ckeditor image upload giving wrong url of the image

114 views
Skip to first unread message

Robin Lery

unread,
Oct 17, 2013, 12:42:15 PM10/17/13
to django...@googlegroups.com

When I try text editing and other text related stuffs and save it, the editor does its job nicely. But when I try to upload an image it just take a different url. I am on windows. Is it because of this, cause I saw a post on this post, but it didn't helped me either. It does get saved and they each have their own thumbnails too. But its just that the wrong urls. I checked the src of the image, and it was like this,

<img alt="" src="/media/3/10/17Hydrangeas.jpg" />

But it should have been like this,

<img alt="" src="/media/2013/10/17/Hydrangeas.jpg" />

And sometimes the src of the image is just like this,

<img alt="" src="/media/3/10/17" />

This is the snippet of my settings.py:

CKEDITOR_UPLOAD_PATH = 'C:/Users/Nanyoo/web/demo/media'
MEDIA_ROOT = 'C:/Users/Nanyoo/web/demo/media'

I've included its url in my urls.py:

(r'^ckeditor/', include('ckeditor.urls')),

models.py:

from django.db import models
from datetime import datetime
from django.contrib.auth.models import User
from time import time


def get_upload_file_name(instance, filename):
    return "uploaded_files/%s_%s" %(str(time()).replace('.','_'), filename)

class Blog(models.Model):
    title = models.CharField(max_length=200)
    image = models.ImageField(upload_to=get_upload_file_name, blank=True)
    pub_date = models.DateTimeField(default=datetime.now)
    creator = models.ForeignKey(User, related_name="creator_set")
    body = models.TextField()

In the forms.py:

from django import forms
from django_summernote.widgets import SummernoteWidget
from ckeditor.widgets import CKEditorWidget

class BlogForm(forms.Form):
    title = forms.CharField(max_length=200,widget=SummernoteWidget())
    body = forms.CharField(widget=CKEditorWidget())

In the index.html:

        {% for blog in blogs %}
        <div id="page">
                <h1>{{ blog.title | safe}}</h1>
                <p>{{ blog.body | safe}}</p>
        </div>
        {% endfor %}

Please help me figure it out. Any help will be greatly appreciated!

Thanks!

Reply all
Reply to author
Forward
0 new messages