0

I've ported a website from a server to another few days ago. Now I need to complete the port, updating the database in the new server.

I've done it, but i get a strange error. It doesn't show me images.

In the database the image field contains https://www.domain.ext/media/uploads/homepage/image_name.jpg but in the admin panel the url is not like that, is like MEDIA_URL (set up in settings.py file) and image field from the database, so if MEDIA_URL is set up like https://www.domain.ext/media/ , in the admin panel in the image field I'll see https://www.domain.ext/media/https://www.domain.ext/media/uploads/folder/image_name.jpg.

I've tried to amend manually the link in db leaving only /uploads/folder/image_name.jpg, I've refreshed the admin page and it seemed ok, but when I saved, it was another time in the wrong form.

Who is so kind to explain me why, and how I can manage with that?

EDIT:

Django Version is 1.2.5

Another issue i saw is that if there is http in MEDIA_URL the behaviour is the same as I have explained . If there is https the url become /https:/www. ...etc... . For this latter, I tried to put an u before the MEDIA_URL string, like MEDIA_URL = u"text" but it didn't work.

Cornelius
  • 1
  • 2
  • How are you creating/editing these objects? – Daniel Roseman Dec 23 '14 at 12:30
  • From the db, do you think this could be the problem? – Cornelius Dec 23 '14 at 12:35
  • I don't know what "from the db" means. Exactly what are you doing? How did you create them originally? – Daniel Roseman Dec 23 '14 at 12:37
  • Originally them was created using Django admin panel. – Cornelius Dec 23 '14 at 12:45
  • @DanielRoseman : Do you think that it's possible to exclude the `MEDIA_URL` from the admin panel, only for certain elements ? Or, in alternative, how i can tell to Django "these urls already contains the `MEDIA_URL`, it's not needed that you add it" ? – Cornelius Dec 23 '14 at 13:59
  • Ok, now I got that the problem is not in the `MEDIA_URL` but in the string . I mean, if the string is like `http://www.domain.ext` it's all ok, and it works, if the string is with the `https` , so is like `https://www.domain.ext` . Django has problems and urls become like `/https:/www.domain.ext/media/http://www.domain.ext/media/uploads/image_name.jpg` . Any ideas ? – Cornelius Dec 23 '14 at 14:13
  • So you are saying that you can manually edit the DB to leave out the domain name from the URL, but when you re-save the model, it puts the domain name back in? Sounds like bad Form/Model code to me! I'd look at the form_valid() method to see what's going on. – Nostalg.io Dec 23 '14 at 20:17
  • The form_valid() method seems ok. It's possible that the reason is that I'm using FileBrowser to select files ? – Cornelius Dec 24 '14 at 08:05

1 Answers1

0

Finally i got the problem!

The problem was in the filebrowser module.

In filebrowser/functions.py there is a method named url_join that was defined like:

def url_join(*args):
"""
URL join routine.
"""

if args[0].startswith("http://"):
    url = "http://"
else:
    url = "/"
for arg in args:
    arg = arg.replace("\\", "/")
    arg_split = arg.split("/")
    for elem in arg_split:
        if elem != "" and elem != "http:":
            url = url + elem + "/"
# remove trailing slash for filenames
if os.path.splitext(args[-1])[1]:
    url = url.rstrip("/")
return url

I simply added an s where there is http so now it's https and it works. It writes the correct thing in the db and it also render the url in the correct way.

Thanks to all for help! :)

EDIT:

Merry Christmas to all! :)

Cornelius
  • 1
  • 2