Model opinnions

48 views
Skip to first unread message

durir...@gmail.com

unread,
Jul 24, 2015, 7:47:26 AM7/24/15
to Django users
I'm doing a little app that consists of a web page were users submits their jokes (https://github.com/RompePC/django-muro_humoristas/tree/feature). I had finished the models (a little overview would help), but I have one question.

I want to use an avatar field for the users: however, I don't understand well for what is MEDIA_URL (also, I would want to know where you would put your MEDIA_ROOT, in a folder of the app, or in a directory as one that gives the example https://docs.djangoproject.com/en/1.8/ref/settings/#std:setting-MEDIA_ROOT).

Thanks (and sorry if anyone doesn't understand spanish hehe).

Gergely Polonkai

unread,
Jul 25, 2015, 3:24:22 PM7/25/15
to django...@googlegroups.com

MEDIA_URL is a prefix that you will put in front of the URL media files. E.g. you set your webserver to load such files under the /media/ URL, like www.example.com/media/my-video.webm. Using different storage backends, like an Amazon S3 bucket, you may want to set this to the bucket's URL.

However, you can even outsource avatar handling to some provider, like Gravatar (which is a totally different topic, though).

I'm doing a little app that consists of a web page were users submits their jokes (https://github.com/RompePC/django-muro_humoristas/tree/feature). I had finished the models (a little overview would help), but I have one question.

I want to use an avatar field for the users: however, I don't understand well for what is MEDIA_URL (also, I would want to know where you would put your MEDIA_ROOT, in a folder of the app, or in a directory as one that gives the example https://docs.djangoproject.com/en/1.8/ref/settings/#std:setting-MEDIA_ROOT).

Thanks (and sorry if anyone doesn't understand spanish hehe).

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fddd7d84-04d3-4e88-ab8c-a75fb5b4e673%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

durir...@gmail.com

unread,
Jul 25, 2015, 4:59:37 PM7/25/15
to Django users, durir...@gmail.com
Nah, I just want to have an avatar inside, to get easy.

And I tried the media docs a few hours ago, but for some reason it doesn't work. I've to set specific URL in urls.py of the app? (Also notice that I use another folder inside media, but I don't think that's the problem).

Gergely Polonkai

unread,
Jul 25, 2015, 5:14:58 PM7/25/15
to django...@googlegroups.com, durir...@gmail.com

Do you save your avatar images there? Do you prepend MEDIA_URL to the avatar's src=""? How do you display the image by the way?

These are the quick questions that came into my mind without knowing your setup…

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

durir...@gmail.com

unread,
Jul 26, 2015, 5:57:51 AM7/26/15
to Django users, ger...@polonkai.eu
Yeah, there is a test image to do the work. But I'm not using HTML elements to see it: I'm trying to directly see it with the URL, like when you open a Twitter image in a new tab.

About the setup...
MEDIA_ROOT = os.path.join(BASE_DIR, '/media/')
MEDIA_URL = '/media/'
So localhost:8000/media/images/avatar.jpg would work, isn't it?

Gergely Polonkai

unread,
Jul 26, 2015, 8:19:38 AM7/26/15
to durir...@gmail.com, Django users

It should, yes. But instead hardcoding /media in your templates, use {{ MEDIA_URL }}

durir...@gmail.com

unread,
Jul 27, 2015, 6:17:47 AM7/27/15
to Django users, ger...@polonkai.eu
It seems that my last message didn't submitted for some reason, but whatever. I found the problem: it was the MEDIA_ROOT. And because of such a noob like me.

Correct:
os.path.join(BASE_DIR, 'myApp/media/')
Wrong:
os.path.join(BASE_DIR, '/media/')
Also correct (media is below "myProject"):
os.path.join(BASE_DIR, 'media/')

I saw the path for the SQLite file and everything had sense. Noob powah.
Reply all
Reply to author
Forward
0 new messages