Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Working with static media files, {{ MEDIA_URL }} shows up blank even with settings.py set [RSS Feed]

#1 Dec. 27, 2010 15:41:11

Lee C.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Working with static media files, {{ MEDIA_URL }} shows up blank even with settings.py set


I have my media url and root set:

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(os.path.abspath(os.path.dirname(__file__)),
'media')

This is what my template has:

<html>
<head>
<title>Postfix Log Viewer</title>
<link rel="stylesheet" href="{{ MEDIA_URL }}css/log.css"
type="text/css">
</head>
<body>

The {{ MEDIA_URL }} shows up blank

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Dec. 27, 2010 16:04:00

e.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Working with static media files, {{ MEDIA_URL }} shows up blank even with settings.py set


I had this same issue before and it was due to
TEMPLATE_CONTEXT_PROCESSORS being missing. Try adding code below in
settings.py if not already there.

TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.request',
)

On Dec 27, 3:17 pm, Lee Connell <lee.a.conn...@gmail.com> wrote:
> I have my media url and root set:
>
> MEDIA_URL = '/media/'
> MEDIA_ROOT = os.path.join(os.path.abspath(os.path.dirname(__file__)),
> 'media')
>
> This is what my template has:
>
> <html>
>     <head>
>         <title>Postfix Log Viewer</title>
>         <link rel="stylesheet" href="{{ MEDIA_URL }}css/log.css"
> type="text/css">
>     </head>
> <body>
>
> The {{ MEDIA_URL }} shows up blank

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Dec. 28, 2010 11:23:43

Kenneth G.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Working with static media files, {{ MEDIA_URL }} shows up blank even with settings.py set


On Mon, 2010-12-27 at 08:03 -0800, easylancer wrote:
> TEMPLATE_CONTEXT_PROCESSORS = (
> 'django.contrib.auth.context_processors.auth',
> 'django.core.context_processors.debug',
> 'django.core.context_processors.i18n',
> 'django.core.context_processors.media',
> 'django.contrib.messages.context_processors.messages',
> 'django.core.context_processors.request',
> )

actually only 'request' is not there - the others are present by default
--
regards
KGhttp://lawgon.livejournal.comCoimbatore LUG roxhttp://ilugcbe.techstud.org/--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 Dec. 28, 2010 15:02:49

Lee C.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Working with static media files, {{ MEDIA_URL }} shows up blank even with settings.py set


I didn't have TEMPLATE_CONTEXT_PROCESSORS at all, I copied the code
and it did not help, MEDIA_URL is still blank. I am using django 1.2.1
on windows.

On Dec 28, 12:56 am, Kenneth Gonsalves <law...@thenilgiris.com> wrote:
> On Mon, 2010-12-27 at 08:03 -0800, easylancer wrote:
> > TEMPLATE_CONTEXT_PROCESSORS = (
> >     'django.contrib.auth.context_processors.auth',
> >     'django.core.context_processors.debug',
> >     'django.core.context_processors.i18n',
> >     'django.core.context_processors.media',
> >     'django.contrib.messages.context_processors.messages',
> >     'django.core.context_processors.request',
> > )
>
> actually only 'request' is not there - the others are present by default
> --
> regards
> KGhttp://lawgon.livejournal.com> Coimbatore LUG roxhttp://ilugcbe.techstud.org/--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#5 Dec. 28, 2010 18:03:27

e.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Working with static media files, {{ MEDIA_URL }} shows up blank even with settings.py set


Post your settings.py in a pastebin and add a link to it here. Remove
all sensitive data before posting it.

On Dec 28, 3:02 pm, Lee Connell <lee.a.conn...@gmail.com> wrote:
> I didn't have TEMPLATE_CONTEXT_PROCESSORS at all, I copied the code
> and it did not help, MEDIA_URL is still blank. I am using django 1.2.1
> on windows.
>
> On Dec 28, 12:56 am, Kenneth Gonsalves <law...@thenilgiris.com> wrote:
>
>
>
>
>
>
>
> > On Mon, 2010-12-27 at 08:03 -0800, easylancer wrote:
> > > TEMPLATE_CONTEXT_PROCESSORS = (
> > >     'django.contrib.auth.context_processors.auth',
> > >     'django.core.context_processors.debug',
> > >     'django.core.context_processors.i18n',
> > >     'django.core.context_processors.media',
> > >     'django.contrib.messages.context_processors.messages',
> > >     'django.core.context_processors.request',
> > > )
>
> > actually only 'request' is not there - the others are present by default
> > --
> > regards
> > KGhttp://lawgon.livejournal.com> > Coimbatore LUG roxhttp://ilugcbe.techstud.org/--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#6 Dec. 28, 2010 19:48:16

Daniel R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Working with static media files, {{ MEDIA_URL }} shows up blank even with settings.py set


On Tuesday, December 28, 2010 3:02:44 PM UTC, Lee Connell wrote:
>
> I didn't have TEMPLATE_CONTEXT_PROCESSORS at all, I copied the code
> and it did not help, MEDIA_URL is still blank. I am using django 1.2.1
> on windows.
>

You don't actually need to specify TEMPLATE_CONTEXT_PROCESSORS if you are
not changing it from the default - which, as indicated above, already
includes the media one.

The issue here is more likely to be that you are not using a RequestContext
to render your template. Seehttp://docs.djangoproject.com/en/1.2/ref/templates/api/#subclassing-context-requestcontext--
DR.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#7 Dec. 28, 2010 22:31:32

dmitry b.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Working with static media files, {{ MEDIA_URL }} shows up blank even with settings.py set


you need to be also using RequestContext in your view instead of the
regular Context. What does your view method's return statement look
like?

On Dec 28, 7:02 am, Lee Connell <lee.a.conn...@gmail.com> wrote:
> I didn't have TEMPLATE_CONTEXT_PROCESSORS at all, I copied the code
> and it did not help, MEDIA_URL is still blank. I am using django 1.2.1
> on windows.
>
> On Dec 28, 12:56 am, Kenneth Gonsalves <law...@thenilgiris.com> wrote:
>
>
>
>
>
>
>
> > On Mon, 2010-12-27 at 08:03 -0800, easylancer wrote:
> > > TEMPLATE_CONTEXT_PROCESSORS = (
> > >     'django.contrib.auth.context_processors.auth',
> > >     'django.core.context_processors.debug',
> > >     'django.core.context_processors.i18n',
> > >     'django.core.context_processors.media',
> > >     'django.contrib.messages.context_processors.messages',
> > >     'django.core.context_processors.request',
> > > )
>
> > actually only 'request' is not there - the others are present by default
> > --
> > regards
> > KGhttp://lawgon.livejournal.com> > Coimbatore LUG roxhttp://ilugcbe.techstud.org/--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#8 Dec. 28, 2010 22:55:51

Lee C.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Working with static media files, {{ MEDIA_URL }} shows up blank even with settings.py set


Thanks everyone, the problem was indeed not using the RequestContext,
using Context does not automatically include some useful variables
which are retrieved from TEMPLATE_CONTEXT_PROCESSORS that includes
MEDIA_URL as stated above.

Thanks again!

On Dec 28, 5:31 pm, dmitry b <dmitry.ma...@gmail.com> wrote:
> you need to be also using RequestContext in your view instead of the
> regular Context.  What does your view method's return statement look
> like?
>
> On Dec 28, 7:02 am, Lee Connell <lee.a.conn...@gmail.com> wrote:
>
>
>
>
>
>
>
> > I didn't have TEMPLATE_CONTEXT_PROCESSORS at all, I copied the code
> > and it did not help, MEDIA_URL is still blank. I am using django 1.2.1
> > on windows.
>
> > On Dec 28, 12:56 am, Kenneth Gonsalves <law...@thenilgiris.com> wrote:
>
> > > On Mon, 2010-12-27 at 08:03 -0800, easylancer wrote:
> > > > TEMPLATE_CONTEXT_PROCESSORS = (
> > > >     'django.contrib.auth.context_processors.auth',
> > > >     'django.core.context_processors.debug',
> > > >     'django.core.context_processors.i18n',
> > > >     'django.core.context_processors.media',
> > > >     'django.contrib.messages.context_processors.messages',
> > > >     'django.core.context_processors.request',
> > > > )
>
> > > actually only 'request' is not there - the others are present by default
> > > --
> > > regards
> > > KGhttp://lawgon.livejournal.com> > > Coimbatore LUG roxhttp://ilugcbe.techstud.org/--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » Working with static media files, {{ MEDIA_URL }} shows up blank even with settings.py set [RSS Feed]

Board footer

Moderator control

Enjoy the 23rd of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support