Re: How force DJANGo choice MEDIA_URL or STATIC_URL in template?

2016-03-02 Thread setivolkylany
I am solved problem next variant:

in model
--

@property
def account_user_picture(self):
if self.picture:
return self.picture.url
else:
return settings.STATIC_URL + 
'project_static/images/default-picture.png'

in templates
--



And all worked

Thanks

среда, 2 марта 2016 г., 1:41:28 UTC+2 пользователь James Schneider написал:
>
>
>> I need choice base url MEDIA_URL (/media/) - for uploaded user picture, 
>> or STATIC_URL (/static/) - picture by default
>>
>> I am try next:
>>
>> p>> alt="picture_for_{{ account.name }}" id="account_picture">
>>
>> , but result is MEDIA_URL(STATIC_URL) and path to file.
>>  
>>
>
> You should work your {% if %} statement this way:
>
> {% if account.accountuserinfo.picture %}
> 
> {% else %}
> 
> {% endif %}
>
> Trying to cram all of that together within the template is awful to read, 
> and doesn't work as you've seen.
>
> It would also make more sense to have the URL path of the default image 
> set somewhere other than inside of a property. Either as a global variable 
> for the model class, or even within your settings.py file and brought in as 
> part of the template context if it can be used by other areas of the 
> system. Querying an object instance for a static value like that is not 
> good style.
>
> -James
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5ea7fc64-b031-4b54-acde-6e745aeb787c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How force DJANGo choice MEDIA_URL or STATIC_URL in template?

2016-03-01 Thread James Schneider
>
>
> I need choice base url MEDIA_URL (/media/) - for uploaded user picture, or
> STATIC_URL (/static/) - picture by default
>
> I am try next:
>
> p> alt="picture_for_{{ account.name }}" id="account_picture">
>
> , but result is MEDIA_URL(STATIC_URL) and path to file.
>
>

You should work your {% if %} statement this way:

{% if account.accountuserinfo.picture %}

{% else %}

{% endif %}

Trying to cram all of that together within the template is awful to read,
and doesn't work as you've seen.

It would also make more sense to have the URL path of the default image set
somewhere other than inside of a property. Either as a global variable for
the model class, or even within your settings.py file and brought in as
part of the template context if it can be used by other areas of the
system. Querying an object instance for a static value like that is not
good style.

-James

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciVZUn-Ks%3DeLQZKz-0aS%3DbrnkKNU3FOy4y7nBYzMmpfEpg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How force DJANGo choice MEDIA_URL or STATIC_URL in template?

2016-03-01 Thread Seti Volkylany
it does not help, because I am image by default


class AccountUserInfo(models.Model):

MAN = 'man'
WOMAN = 'woman'
VAGUE = 'vague'

GENDER_CHOICES = [
(VAGUE, 'Vague'),
(MAN, 'Male'),
(WOMAN, 'Female'),
]

def dispatch_account_media_files(instance, filename):
return '{0}/app_accounts/{1}'.format(instance.account.__str__(),
filename)

account = models.OneToOneField(AccountUser, on_delete=models.CASCADE)
first_name = models.CharField('First name', max_length=50, blank=True,
null=True)
last_name = models.CharField('Last name', max_length=50, blank=True,
null=True)
*picture = models.ImageField('Picture',
upload_to=dispatch_account_media_files, blank=True, null=True)*
gender = models.CharField('Gender', max_length=10,
choices=GENDER_CHOICES, default=GENDER_CHOICES[0][0])
country = CountryField('Country', blank_label='(select country)',
blank=True, null=True)
birthday = models.DateField('Birthday', blank=True, null=True)


--

@property
def picture_url(self):
if self.picture and hasattr(self.picture, 'url'):
return self.picture.url
else:
*return '/project_static/images/default-picture.png'*

But thanks for the advice


On Tue, Mar 1, 2016 at 5:23 PM, Jonas Svensson <jonas.s.svens...@gmail.com>
wrote:

> It seems like you want to use display a default picture if the user does
> not have one.
> {% load static %}
> {% static "images/default_pic.jpg" as default_pic %}
> {{ account.accountuserinfo.picture|default:default_pic }}
>
> Cheers
>
> On Monday, February 29, 2016 at 10:49:53 PM UTC+1, setivo...@gmail.com
> wrote:
>>
>>
>> I need choice base url MEDIA_URL (/media/) - for uploaded user picture,
>> or STATIC_URL (/static/) - picture by default
>>
>> I am try next:
>>
>> p>> alt="picture_for_{{ account.name }}" id="account_picture">
>>
>> , but result is MEDIA_URL(STATIC_URL) and path to file.
>>
>> I am next try:
>>
>> {% templatetag openvariable %} url 'entry_list' {% templatetag closevariable 
>> %}
>>
>>
>> but result is {{ MEDIA_URL }} or {{ STATIC_URL }} (not working)
>>
>> may by anyone known how solved this problem
>> ---
>>
>> Thanks
>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/5ZJzHbs1sYY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/ad20612d-2a90-4108-8737-d4bbe99a262c%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/ad20612d-2a90-4108-8737-d4bbe99a262c%40googlegroups.com?utm_medium=email_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGWd_9KBPvrmeVGzNjfrmqAyV5%2BHZaAEsN0DjJtjxVOV2VG%2B1A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How force DJANGo choice MEDIA_URL or STATIC_URL in template?

2016-03-01 Thread Jonas Svensson
It seems like you want to use display a default picture if the user does 
not have one.
{% load static %}
{% static "images/default_pic.jpg" as default_pic %}
{{ account.accountuserinfo.picture|default:default_pic }}

Cheers

On Monday, February 29, 2016 at 10:49:53 PM UTC+1, setivo...@gmail.com 
wrote:
>
>
> I need choice base url MEDIA_URL (/media/) - for uploaded user picture, or 
> STATIC_URL (/static/) - picture by default
>
> I am try next:
>
> p> alt="picture_for_{{ account.name }}" id="account_picture">
>
> , but result is MEDIA_URL(STATIC_URL) and path to file.
>
> I am next try:
>
> {% templatetag openvariable %} url 'entry_list' {% templatetag closevariable 
> %}
>
>
> but result is {{ MEDIA_URL }} or {{ STATIC_URL }} (not working)
>
> may by anyone known how solved this problem
> ---
>
> Thanks
>
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ad20612d-2a90-4108-8737-d4bbe99a262c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How force DJANGo choice MEDIA_URL or STATIC_URL in template?

2016-02-29 Thread setivolkylany

I need choice base url MEDIA_URL (/media/) - for uploaded user picture, or 
STATIC_URL (/static/) - picture by default

I am try next:

p>

, but result is MEDIA_URL(STATIC_URL) and path to file.

I am next try:

{% templatetag openvariable %} url 'entry_list' {% templatetag closevariable %}


but result is {{ MEDIA_URL }} or {{ STATIC_URL }} (not working)

may by anyone known how solved this problem
---

Thanks

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/72159edf-e841-41ce-8513-571b142d4f24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is there a way to make the template process {{ MEDIA_URL }} if it is stored in a model field.

2015-08-30 Thread Dennis Marwood
Ok, thanks. It seems like such a common use case that I wanted to be sure 
there was not an existing template tag for it.


On Sunday, 30 August 2015 14:48:47 UTC-7, Christophe Pettus wrote:
>
>
> On Aug 30, 2015, at 2:37 PM, Christophe Pettus  > wrote: 
>
> > On Aug 30, 2015, at 12:43 PM, Dennis Marwood  > wrote: 
> > 
> >> How do I get the template to treat {{ }} in my entry as a variable? 
> > 
> > The Django template language doesn't iterate over the results of 
> expansion; once a substitution is done, it moves on.  So, template language 
> constructs that "appear" in the result due to variable expansion. 
>
> As a note, this is a feature, not a bug: If template expansion iterated 
> like that, it would be a serious security hole, since someone could drop 
> template items ( {{ entry.delete }}, anyone?) into user-edited content.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/bad2c6f3-cdf4-447d-87e1-9a50f439efd9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is there a way to make the template process {{ MEDIA_URL }} if it is stored in a model field.

2015-08-30 Thread Christophe Pettus

On Aug 30, 2015, at 2:37 PM, Christophe Pettus  wrote:

> On Aug 30, 2015, at 12:43 PM, Dennis Marwood  wrote:
> 
>> How do I get the template to treat {{ }} in my entry as a variable?
> 
> The Django template language doesn't iterate over the results of expansion; 
> once a substitution is done, it moves on.  So, template language constructs 
> that "appear" in the result due to variable expansion.

As a note, this is a feature, not a bug: If template expansion iterated like 
that, it would be a serious security hole, since someone could drop template 
items ( {{ entry.delete }}, anyone?) into user-edited content.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/7995C1A8-4DAB-4E59-B661-325D93A8E9AB%40thebuild.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is there a way to make the template process {{ MEDIA_URL }} if it is stored in a model field.

2015-08-30 Thread Christophe Pettus

On Aug 30, 2015, at 12:43 PM, Dennis Marwood  wrote:

> How do I get the template to treat {{ }} in my entry as a variable?

The Django template language doesn't iterate over the results of expansion; 
once a substitution is done, it moves on.  So, template language constructs 
that "appear" in the result due to variable expansion

You could do this by building the template up programmatically, and then 
passing the output of that process to the appropriate render method. You could 
also (probably better) write a custom template tag that does the right thing.

--
-- Christophe Pettus
   x...@thebuild.com

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/524E4D09-5384-41BF-A43D-4C650944C53F%40thebuild.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is there a way to make the template process {{ MEDIA_URL }} if it is stored in a model field.

2015-08-30 Thread Dennis Marwood
So you are saying I should alter the models save method to do a search and 
replace on the entry field?

On Sunday, 30 August 2015 14:03:18 UTC-7, monoBOT monoBOT wrote:
>
> You can import your any part of your settings into the model.py file and 
> then insert it
>
> like this:
>
> from django.conf import MEDIA_URL
>
>
> 2015-08-30 20:43 GMT+01:00 Dennis Marwood <dennis...@gmail.com 
> >:
>
>> Hello,
>>
>> I have a seemingly straight forward and likely common issue. But there is 
>> no obvious way that I am seeing to make it work.
>>
>> I have a Blog model with a text field called entry. I want to put 
>> something like 
>>
>> 
>>
>> into the blog post. So Blog.entry would contain it. Then I use the 
>> template to display my blog post like
>>
>> {% for post in posts %} {{ post.entry }} {% endfor %}
>>
>> But the template does not process {{ MEDIA_URL }}. It just sees it as a 
>> string and prints it exactly as passed in.
>>
>> How do I get the template to treat {{ }} in my entry as a variable? How 
>> can I get that value substituted? I have used a custom template filter in 
>> the past. But this has got to be a very common use case. It seems like 
>> there would be some built in django way to get this to work?
>>
>> Thanks,
>> Dennis
>>
>> -- 
>> 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/60b7bdc9-f396-4ffd-b4ff-10a7dd5931c0%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/60b7bdc9-f396-4ffd-b4ff-10a7dd5931c0%40googlegroups.com?utm_medium=email_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> *monoBOT*
> Visite mi sitio(Visit my site): monobotsoft.es/blog/
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/99e5bce9-1537-4bd1-99b1-a2b6e14aa64b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is there a way to make the template process {{ MEDIA_URL }} if it is stored in a model field.

2015-08-30 Thread monoBOT
You can import your any part of your settings into the model.py file and
then insert it

like this:

from django.conf import MEDIA_URL


2015-08-30 20:43 GMT+01:00 Dennis Marwood <dennismarw...@gmail.com>:

> Hello,
>
> I have a seemingly straight forward and likely common issue. But there is
> no obvious way that I am seeing to make it work.
>
> I have a Blog model with a text field called entry. I want to put
> something like
>
> 
>
> into the blog post. So Blog.entry would contain it. Then I use the
> template to display my blog post like
>
> {% for post in posts %} {{ post.entry }} {% endfor %}
>
> But the template does not process {{ MEDIA_URL }}. It just sees it as a
> string and prints it exactly as passed in.
>
> How do I get the template to treat {{ }} in my entry as a variable? How
> can I get that value substituted? I have used a custom template filter in
> the past. But this has got to be a very common use case. It seems like
> there would be some built in django way to get this to work?
>
> Thanks,
> Dennis
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@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/60b7bdc9-f396-4ffd-b4ff-10a7dd5931c0%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/60b7bdc9-f396-4ffd-b4ff-10a7dd5931c0%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*monoBOT*
Visite mi sitio(Visit my site): monobotsoft.es/blog/

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/CA%2BxOsGDaVDWA_xeP%2BwBSdYE%2BeMH6NcZUoDRXA6fJ%2BzOhrwhCCA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Is there a way to make the template process {{ MEDIA_URL }} if it is stored in a model field.

2015-08-30 Thread Dennis Marwood
Hello,

I have a seemingly straight forward and likely common issue. But there is 
no obvious way that I am seeing to make it work.

I have a Blog model with a text field called entry. I want to put something 
like 



into the blog post. So Blog.entry would contain it. Then I use the template 
to display my blog post like

{% for post in posts %} {{ post.entry }} {% endfor %}

But the template does not process {{ MEDIA_URL }}. It just sees it as a 
string and prints it exactly as passed in.

How do I get the template to treat {{ }} in my entry as a variable? How can 
I get that value substituted? I have used a custom template filter in the 
past. But this has got to be a very common use case. It seems like there 
would be some built in django way to get this to work?

Thanks,
Dennis

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/60b7bdc9-f396-4ffd-b4ff-10a7dd5931c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: MEDIA_URL doesnt work in windows but works on linux

2015-04-14 Thread Stephen J. Butler
How doesn't it work?

1. Does the uploaded file appear where you expect it to?
2. If you construct the URL properly in your browser, can you access
it directly?
3. What is the URL being output in your templates?


On Tue, Apr 14, 2015 at 9:44 AM, dk <demi...@gmail.com> wrote:
> maybe I need to simplify my question.
>
>
> how do I use media_url  in windows?
>
>
>
>
>
>
> On Wednesday, April 8, 2015 at 10:56:27 AM UTC-5, dk wrote:
>>
>> in my settings
>> MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
>> MEDIA_URL = "/media/"
>>
>>
>> my view to accept files.
>> def request_page(request):
>>  #todo since sqlite my get stuck between 2 submittion at the same time,
>>  # submit, if it cant try again  and then message that ask the user to try
>> in 5 mins.
>>  try:
>>   if request.method == "POST":
>>form = Submit_Form(request.POST, request.FILES)
>>if form.is_valid():
>> email = form.cleaned_data["email"]
>> file = request.FILES["file"]
>> # we make the message true or false so we can display color in the
>> html template.
>> if file.name.endswith(".ini"):
>>  per = Person(email=email, date_submitted=datetime.datetime.now(),
>> file=file)
>>  per.save()
>>  message = ["Thanks, we receive your file:" + email, "True"]
>>  forma = Submit_Form()
>> else:
>>  message = ["its not the appropriate type of file, please verify.",
>> "False"]
>>  forma = Submit_Form()
>>
>>
>>
>>
>> and this is how I am making my model
>> def content_file_name(instance, filename):
>> here is where I think is the problem,  windows like \ and Linux /  but
>> even using os.path.join   I wasn't able to make it work,
>> I also try hard code the path using \\.join instead
>>  if os.name == "nt":
>>   # path = "\\".join(["submitted_ini_files", filename + "___" +
>> str(instance.email) + "___" + str(datetime.datetime.now())])
>>   path = os.path.join("submitted_ini_files", filename + "___" +
>> str(instance.email) + "___" + str(datetime.datetime.now()))
>>   print path
>>   print MEDIA_URL
>>   # path = os.path.join("submitted_ini_files", filename + "___" +
>> str(instance.email) + "___" + str(datetime.datetime.now() ))
>>   return path
>>  else:
>>   print "other than nt"
>>   return "/".join(["submitted_ini_files", filename + "___" +
>> str(instance.email) + "___" + str(datetime.datetime.now())])
>>
>>
>> class Person(models.Model):
>>  email = models.EmailField(blank=True, null=True)
>>  file = models.FileField(blank=True, null=True,
>> upload_to=content_file_name)
>>  date_submitted = models.DateTimeField(blank=True, null=True)
>>
>> any tips on how to make this work?  thanks.
>>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@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/c4053a51-ec3b-4445-8706-821ee2d539e1%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/CAD4ANxW-FETEmsF%3DvtxJ%2BZ0j5UDwZhqaUyPMUNXivShiyTPJ0w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: MEDIA_URL doesnt work in windows but works on linux

2015-04-14 Thread dk
maybe I need to simplify my question.


how do I use media_url  in windows?






On Wednesday, April 8, 2015 at 10:56:27 AM UTC-5, dk wrote:

> in my settings 
> MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
> MEDIA_URL = "/media/"
>
>
> my view to accept files.
> def request_page(request):
>  #todo since sqlite my get stuck between 2 submittion at the same time,
>  # submit, if it cant try again  and then message that ask the user to try 
> in 5 mins.
>  try:
>   if request.method == "POST":
>form = Submit_Form(request.POST, request.FILES)
>if form.is_valid():
> email = form.cleaned_data["email"]
> file = request.FILES["file"]
> # we make the message true or false so we can display color in the 
> html template.
> if file.name.endswith(".ini"):
>  per = Person(email=email, date_submitted=datetime.datetime.now(), 
> file=file)
>  per.save()
>  message = ["Thanks, we receive your file:" + email, "True"]
>  forma = Submit_Form()
> else:
>  message = ["its not the appropriate type of file, please verify.", 
> "False"]
>  forma = Submit_Form()
>
>
>
>
> and this is how I am making my model
> def content_file_name(instance, filename):
> here is where I think is the problem,  windows like \ and Linux /  
> but even using os.path.join   I wasn't able to make it work, 
> I also try hard code the path using \\.join instead
>  if os.name == "nt":
>   # path = "\\".join(["submitted_ini_files", filename + "___" + 
> str(instance.email) + "___" + str(datetime.datetime.now())])
>   path = os.path.join("submitted_ini_files", filename + "___" + 
> str(instance.email) + "___" + str(datetime.datetime.now()))
>   print path
>   print MEDIA_URL
>   # path = os.path.join("submitted_ini_files", filename + "___" + 
> str(instance.email) + "___" + str(datetime.datetime.now() ))
>   return path
>  else:
>   print "other than nt"
>   return "/".join(["submitted_ini_files", filename + "___" + 
> str(instance.email) + "___" + str(datetime.datetime.now())])
>
>
> class Person(models.Model):
>  email = models.EmailField(blank=True, null=True)
>  file = models.FileField(blank=True, null=True, 
> upload_to=content_file_name)
>  date_submitted = models.DateTimeField(blank=True, null=True)
>
> any tips on how to make this work?  thanks.  
>
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/c4053a51-ec3b-4445-8706-821ee2d539e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


MEDIA_URL doesnt work in windows but works on linux

2015-04-08 Thread dk
in my settings 
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = "/media/"


my view to accept files.
def request_page(request):
 #todo since sqlite my get stuck between 2 submittion at the same time,
 # submit, if it cant try again  and then message that ask the user to try 
in 5 mins.
 try:
  if request.method == "POST":
   form = Submit_Form(request.POST, request.FILES)
   if form.is_valid():
email = form.cleaned_data["email"]
file = request.FILES["file"]
# we make the message true or false so we can display color in the html 
template.
if file.name.endswith(".ini"):
 per = Person(email=email, date_submitted=datetime.datetime.now(), 
file=file)
 per.save()
 message = ["Thanks, we receive your file:" + email, "True"]
 forma = Submit_Form()
else:
 message = ["its not the appropriate type of file, please verify.", 
"False"]
 forma = Submit_Form()




and this is how I am making my model
def content_file_name(instance, filename):
here is where I think is the problem,  windows like \ and Linux /  but even 
using os.path.join   I wasn't able to make it work, 
I also try hard code the path using \\.join instead
 if os.name == "nt":
  # path = "\\".join(["submitted_ini_files", filename + "___" + 
str(instance.email) + "___" + str(datetime.datetime.now())])
  path = os.path.join("submitted_ini_files", filename + "___" + 
str(instance.email) + "___" + str(datetime.datetime.now()))
  print path
  print MEDIA_URL
  # path = os.path.join("submitted_ini_files", filename + "___" + 
str(instance.email) + "___" + str(datetime.datetime.now() ))
  return path
 else:
  print "other than nt"
  return "/".join(["submitted_ini_files", filename + "___" + 
str(instance.email) + "___" + str(datetime.datetime.now())])


class Person(models.Model):
 email = models.EmailField(blank=True, null=True)
 file = models.FileField(blank=True, null=True, upload_to=content_file_name)
 date_submitted = models.DateTimeField(blank=True, null=True)

any tips on how to make this work?  thanks.  

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@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/8c9548cd-304a-4d06-bf84-ada8504612d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: AW: MEDIA_URL not treated like static

2011-03-28 Thread galgal
Thanks, I didn't know that. All works fine now.

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



Re: AW: MEDIA_URL not treated like static

2011-03-28 Thread Amao Zhao
Dear galgal:
according to the django docs for 1.3, The most likely example is
user-uploaded content in
MEDIA_ROOT
. staticfiles is intended for static assets and has no built-in handling for
user-uploaded files, but you can have Django serve your
MEDIA_ROOT
by
appending something like this to your URLconf.
And you can read the doc with
http://docs.djangoproject.com/en/1.3/howto/static-files/#serving-other-directories

On Mon, Mar 28, 2011 at 7:48 PM, galgal  wrote:

> I forgot to tell I'm using Django 1.3. In that case - how to make it work
> with separate dirs? Or it can't be done on dev server?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: AW: MEDIA_URL not treated like static

2011-03-28 Thread galgal
I forgot to tell I'm using Django 1.3. In that case - how to make it work 
with separate dirs? Or it can't be done on dev server?

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



AW: MEDIA_URL not treated like static

2011-03-28 Thread Szabo, Patrick (LNG-VIE)
I have a static folder in my Prject and my MEDIA_URL looks like this: 
http://127.0.0.1:8000/static/

 

Von: django-users@googlegroups.com [mailto:django-users@googlegroups.com] Im 
Auftrag von galgal
Gesendet: Montag, 28. März 2011 13:38
An: django-users@googlegroups.com
Betreff: MEDIA_URL not treated like static

 

I have that dirs structure:

site_media/

|
---> static/

|

---> uploads/

 

static dir is set as STATIC_URL = '/site_media/static/'

uploads dir is set as MEDIA_URL = '/site_media/uploads/'

 

In that case on dev server (localhost:8000) media_url is not accessible via 
browser as static file, and whe I try to access it I get 404 error. How can i 
set it up to be seen as static?

In uploads dir are all files uploaded by users. static dir includes all my 
js/css/images

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


. . . . . . . . . . . . . . . . . . . . . . . . . .
Patrick Szabo
 XSLT Developer 
LexisNexis
Marxergasse 25, 1030 Wien

mailto:patrick.sz...@lexisnexis.at
Tel.: +43 (1) 534 52 - 1573 
Fax: +43 (1) 534 52 - 146 





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



MEDIA_URL not treated like static

2011-03-28 Thread galgal
I have that dirs structure:
site_media/
|
---> static/
|
---> uploads/

static dir is set as STATIC_URL = '/site_media/static/'
uploads dir is set as MEDIA_URL = '/site_media/uploads/'

In that case on dev server (localhost:8000) media_url is not accessible via 
browser as static file, and whe I try to access it I get 404 error. How can 
i set it up to be seen as static?
In uploads dir are all files uploaded by users. static dir includes all my 
js/css/images

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



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

2010-12-28 Thread Lee Connell
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 at 
http://groups.google.com/group/django-users?hl=en.



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

2010-12-28 Thread dmitry b
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 at 
http://groups.google.com/group/django-users?hl=en.



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

2010-12-28 Thread Daniel Roseman
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. See 
http://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 at 
http://groups.google.com/group/django-users?hl=en.



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

2010-12-28 Thread easylancer
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 at 
http://groups.google.com/group/django-users?hl=en.



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

2010-12-28 Thread Lee Connell
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 at 
http://groups.google.com/group/django-users?hl=en.



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

2010-12-28 Thread Kenneth Gonsalves
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
KG
http://lawgon.livejournal.com
Coimbatore LUG rox
http://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 at 
http://groups.google.com/group/django-users?hl=en.



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

2010-12-27 Thread easylancer
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:
>
> 
>     
>         Postfix Log Viewer
>          type="text/css">
>     
> 
>
> 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 at 
http://groups.google.com/group/django-users?hl=en.



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

2010-12-27 Thread Lee Connell
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:



Postfix Log Viewer




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 at 
http://groups.google.com/group/django-users?hl=en.



Re: do we need MEDIA_ROOT and MEDIA_URL anymore?

2010-11-17 Thread Adam V.


On Nov 17, 2:07 am, MiratCanBayrak <miratcanbay...@gmail.com> wrote:
> Hi,
>
> I understood that in new version of django we are using
> STATICFILES_ROOT and STATICFILES_URL instead OF MEDIA_ROOT and
> MEDIA_URL.
>
> But when i look at settings.py i see both of them. When do we use
> MEDIA? when do we use STATICFILES ?
>
> Note: pls dont give link to docs i already read them

Staticfiles are for serving js/css/img that come with apps; Media is
for accepting uploads of files (and possibly also serving them back
out.)

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



do we need MEDIA_ROOT and MEDIA_URL anymore?

2010-11-17 Thread MiratCanBayrak
Hi,

I understood that in new version of django we are using
STATICFILES_ROOT and STATICFILES_URL instead OF MEDIA_ROOT and
MEDIA_URL.

But when i look at settings.py i see both of them. When do we use
MEDIA? when do we use STATICFILES ?

Note: pls dont give link to docs i already read them

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: Using localhost in MEDIA_URL causing very slow django

2010-08-16 Thread Steve Holden
On 8/16/2010 2:25 AM, Martin Lundberg wrote:
> Hi,
> 
> I started having a problem on my website when working on it locally
> using the runserver dev server. If I started the server I could visit
> a page once (and it loaded quickly) but if I reloaded the page it
> could take like 10 minutes for it to load. The code didn't even reach
> the view. I tracked the problem down to the use of MEDIA_URL in my
> base.html. I looked at my MEDIA_URL setting and it was set to
> http://localhost:8000/media/. Since I'm using http://127.0.0.1:8000/
> to access the page I tried changing the setting to 127.0.0.1 as well
> and for some reason the problem went away.
> 
> I'm curious to know if someone know why this was a problem?¨
> 
I would suspect a DNS issue - though this doesn't off-hand explain to me
why the page loaded so quickly the first time.

regards
 Steve
-- 
DjangoCon US 2010 September 7-9 http://djangocon.us/

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Using localhost in MEDIA_URL causing very slow django

2010-08-16 Thread Martin Lundberg
Hi,

I started having a problem on my website when working on it locally
using the runserver dev server. If I started the server I could visit
a page once (and it loaded quickly) but if I reloaded the page it
could take like 10 minutes for it to load. The code didn't even reach
the view. I tracked the problem down to the use of MEDIA_URL in my
base.html. I looked at my MEDIA_URL setting and it was set to
http://localhost:8000/media/. Since I'm using http://127.0.0.1:8000/
to access the page I tried changing the setting to 127.0.0.1 as well
and for some reason the problem went away.

I'm curious to know if someone know why this was a problem?¨

-Martin

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



[Solved] Re: Not reflecting MEDIA_URL value

2010-07-20 Thread barun
Hurray! I had missed this small thing and banging my head for the last
few hours! Thanks a lot to you!

On Jul 20, 4:18 pm, David De La Harpe Golden
<david.delaharpe.gol...@ichec.ie> wrote:
> On 20/07/10 12:11, barun wrote:
>
>
>
> > [gallery/views.py]
> > def index(request):
> >         return render_to_response('base.html', {})
>
> You have to pass through a RequestContext() for the template context
> processor that injects MEDIA_URL
> ('django.core.context_processors.media') into to the template to kick
> in, and you have to have said template context processor in your
> settings.TEMPLATE_CONTEXT_PROCESSORS (it is by default).
>
> i.e. you should be doing
>         return render_to_response(
>             'base.html,
>             {},
>             context_instance=RequestContext(request))
>
> It may well be that pretty much every view you write needs the relevant
> boilerplate.   It's not like it's hard to define your own function to
> hide the verbosity, but some days I kind of wish it was the default (the
> reason it isn't is probably something to do with performance).

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: Not reflecting MEDIA_URL value

2010-07-20 Thread David De La Harpe Golden
On 20/07/10 12:11, barun wrote:
> 
> [gallery/views.py]
> def index(request):
> return render_to_response('base.html', {})
> 

You have to pass through a RequestContext() for the template context
processor that injects MEDIA_URL
('django.core.context_processors.media') into to the template to kick
in, and you have to have said template context processor in your
settings.TEMPLATE_CONTEXT_PROCESSORS (it is by default).

i.e. you should be doing
return render_to_response(
'base.html,
{},
context_instance=RequestContext(request))


It may well be that pretty much every view you write needs the relevant
boilerplate.   It's not like it's hard to define your own function to
hide the verbosity, but some days I kind of wish it was the default (the
reason it isn't is probably something to do with performance).

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Not reflecting MEDIA_URL value

2010-07-20 Thread barun
Hi,

I've a project photo and an application gallery. I want to do a very
simple thing: When the URL http://localhost:8000/gallery/ is accessed,
a page will be displayed containing a single image. I've set the
necessary variables and mapped the URLs.

The problem is, in the base.html template (where I'm using
{{ MEDIA_URL }} to denote the path of the image), the value of the
variable MEDIA_URL is not getting substituted -- it appears as blank.

For example, with the following settings:

[photo/settings.py]
DEBUG = True
MEDIA_ROOT = '/home/barun/codes/python/django/test/photo/media/'
MEDIA_URL = '/gallery/s_media/'

[photo/urls.py]
(r'^gallery/', include('photo.gallery.urls')),

[gallery/urls.py]
urlpatterns = patterns('',
(r'^$', 'photo.gallery.views.index'),
(r'^s_media/(?P.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}),
)

[gallery/views.py]
def index(request):
return render_to_response('base.html', {})

[templates/base.html]



when the HTML page is finally displayed in the browser, the image
source appears as


Could anyone please suggest on this?

Thanks!

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: context porcessors request.context media_url breaks admin

2010-07-08 Thread Rolando Espinoza La Fuente
On Thu, Jul 8, 2010 at 8:21 AM, justin jools <justinjo...@gmail.com> wrote:
> Wow... django docs can be so confusing...
>
> I could not believe it worked just by using upper case MEDIA_URL

{{ MEDIA_URL }} is already present in the templates because the
django.core.context_processors.media  context processor which
is enabled by default*.

You didn't need to create a media_url context processor at all.
And templates tags are called with {% %} .e.g {% media_url %}

Regards

~Rolando

* http://docs.djangoproject.com/en/dev/ref/templates/api/#id1

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: context porcessors request.context media_url breaks admin

2010-07-08 Thread justin jools
Wow... django docs can be so confusing...

I could not believe it worked just by using upper case MEDIA_URL

Thanks so much :) :)

I spent a day trying figure this out...

On 8 July, 13:14, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Jul 8, 12:57 pm, justin jools <justinjo...@gmail.com> wrote:
>
>
>
>
>
> > Thank for your quick response Daniel.
> > I'm just confused about using media_url with generic views, I have
> > done it previously with:
>
> > from django.conf import settings        # for media_url
> > media_url = settings.MEDIA_URL
>
> > def dblist(request):
> >     obj_list_menu = dbModel1.objects.all()
> >     return render_to_response('products/dblist.html', {'make_list':
> > obj_list_menu, 'media_url': media_url })
>
> > but with generic views, have no views.py obviously, so I put it in
> > settings.py:
>
> > from django.conf import settings        # for media_url
> > media_url = settings.MEDIA_URL
>
> > and in my base.html template:
>
> > {{ media_url }}css/base.css
>
> > but it's not picking it up?  do i need to pass it with generic views?
>
> But you don't need to set anything! As I said, generic views already
> have access to MEDIA_URL, as long as you don't remove it from the list
> of installed context processors. So I don't know why you want to
> define another variable called "media_url". Just use the existing
> upper-case one.
> --
> DR.- Hide quoted text -
>
> - Show quoted text -

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: context porcessors request.context media_url breaks admin

2010-07-08 Thread justin jools
The 2 methods of using media_url with generic views I have tried:

1. 
http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/
This knocked out my admin, but media_url did work

2. using templatetags
yourApp/templatetags/media_url.py:

from django.template import Library
from yourapp.settings import MEDIA_URL
register = Library()

@register.simple_tag
def media_url():
return MEDIA_URL
And in my template file:

{% load media_url %}


I could not get either of these methods to work, can you give best
guideline for this,

Thanks,
Justin Jools

On 8 July, 12:35, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Jul 8, 11:40 am, justin jools <justinjo...@gmail.com> wrote:
>
> > Thanks for that. I did read something about having to add services
> > back in to the context processors.
> > The reason I am doing this way is because I could not pass the {media
> > url} with generic views.
> > I did a search for trying to do this and hit a couple of posts saying
> > it is not possible to use {media url} with generic views.
>
> > If you have a solution I would be happy to hear this.
>
> I'd be interested to know where you read this, because in fact the
> opposite is true. Generic views all use the RequestContext, which
> means they automatically gain access to all the existing context
> processors - including the default
> "django.core.context_processors.media" processor. So, all generic
> views *already* have access to MEDIA_URL.
> --
> 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 at 
http://groups.google.com/group/django-users?hl=en.



Re: context porcessors request.context media_url breaks admin

2010-07-08 Thread Daniel Roseman
On Jul 8, 12:57 pm, justin jools <justinjo...@gmail.com> wrote:
> Thank for your quick response Daniel.
> I'm just confused about using media_url with generic views, I have
> done it previously with:
>
> from django.conf import settings        # for media_url
> media_url = settings.MEDIA_URL
>
> def dblist(request):
>     obj_list_menu = dbModel1.objects.all()
>     return render_to_response('products/dblist.html', {'make_list':
> obj_list_menu, 'media_url': media_url })
>
> but with generic views, have no views.py obviously, so I put it in
> settings.py:
>
> from django.conf import settings        # for media_url
> media_url = settings.MEDIA_URL
>
> and in my base.html template:
>
> {{ media_url }}css/base.css
>
> but it's not picking it up?  do i need to pass it with generic views?

But you don't need to set anything! As I said, generic views already
have access to MEDIA_URL, as long as you don't remove it from the list
of installed context processors. So I don't know why you want to
define another variable called "media_url". Just use the existing
upper-case one.
--
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: context porcessors request.context media_url breaks admin

2010-07-08 Thread justin jools
Thank for your quick response Daniel.
I'm just confused about using media_url with generic views, I have
done it previously with:

from django.conf import settings# for media_url
media_url = settings.MEDIA_URL

def dblist(request):
obj_list_menu = dbModel1.objects.all()
return render_to_response('products/dblist.html', {'make_list':
obj_list_menu, 'media_url': media_url })

but with generic views, have no views.py obviously, so I put it in
settings.py:

from django.conf import settings# for media_url
media_url = settings.MEDIA_URL

and in my base.html template:

{{ media_url }}css/base.css

but it's not picking it up?  do i need to pass it with generic views?

On 8 July, 12:35, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Jul 8, 11:40 am, justin jools <justinjo...@gmail.com> wrote:
>
> > Thanks for that. I did read something about having to add services
> > back in to the context processors.
> > The reason I am doing this way is because I could not pass the {media
> > url} with generic views.
> > I did a search for trying to do this and hit a couple of posts saying
> > it is not possible to use {media url} with generic views.
>
> > If you have a solution I would be happy to hear this.
>
> I'd be interested to know where you read this, because in fact the
> opposite is true. Generic views all use the RequestContext, which
> means they automatically gain access to all the existing context
> processors - including the default
> "django.core.context_processors.media" processor. So, all generic
> views *already* have access to MEDIA_URL.
> --
> 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 at 
http://groups.google.com/group/django-users?hl=en.



Re: context porcessors request.context media_url breaks admin

2010-07-08 Thread Daniel Roseman
On Jul 8, 11:40 am, justin jools <justinjo...@gmail.com> wrote:
> Thanks for that. I did read something about having to add services
> back in to the context processors.
> The reason I am doing this way is because I could not pass the {media
> url} with generic views.
> I did a search for trying to do this and hit a couple of posts saying
> it is not possible to use {media url} with generic views.
>
> If you have a solution I would be happy to hear this.

I'd be interested to know where you read this, because in fact the
opposite is true. Generic views all use the RequestContext, which
means they automatically gain access to all the existing context
processors - including the default
"django.core.context_processors.media" processor. So, all generic
views *already* have access to MEDIA_URL.
--
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: context porcessors request.context media_url breaks admin

2010-07-08 Thread justin jools
Thanks for that. I did read something about having to add services
back in to the context processors.
The reason I am doing this way is because I could not pass the {media
url} with generic views.
I did a search for trying to do this and hit a couple of posts saying
it is not possible to use {media url} with generic views.

If you have a solution I would be happy to hear this.

On 29 June, 13:55, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Jun 29, 1:41 pm, justin jools <justinjo...@gmail.com> wrote:
>
> > Hi Tom if you read my original post you will realise that the error is
> > being caused by setting of context processors to media_url (see
> > original post).
> > When context processors are active the {media_url} tag works
> > perfectly, but breaks the admin.
>
> > If I comment out :
> > settings.py
> > #TEMPLATE_CONTEXT_PROCESSORS =
> > ('portfolio.context_processors.media_url',)
> > and
> > urls.py
> > #from django.template import RequestContext
>
> > the admin then works.
>
> You have completely overridden the default template context
> processors. All the functionality that the admin depends on -
> authentication, csrf protection, internationalisation, messages - has
> all now gone thanks to this setting.
>
> You should just *add* your processor to the existing list. However, I
> don't understand why you want to do this at all, given that the
> default list already includes the
> "django.core.context_processors.media" processor which does exactly
> the same as your version.
> --
> 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 at 
http://groups.google.com/group/django-users?hl=en.



Re: context porcessors request.context media_url breaks admin

2010-06-29 Thread Daniel Roseman
On Jun 29, 1:41 pm, justin jools <justinjo...@gmail.com> wrote:
> Hi Tom if you read my original post you will realise that the error is
> being caused by setting of context processors to media_url (see
> original post).
> When context processors are active the {media_url} tag works
> perfectly, but breaks the admin.
>
> If I comment out :
> settings.py
> #TEMPLATE_CONTEXT_PROCESSORS =
> ('portfolio.context_processors.media_url',)
> and
> urls.py
> #from django.template import RequestContext
>
> the admin then works.

You have completely overridden the default template context
processors. All the functionality that the admin depends on -
authentication, csrf protection, internationalisation, messages - has
all now gone thanks to this setting.

You should just *add* your processor to the existing list. However, I
don't understand why you want to do this at all, given that the
default list already includes the
"django.core.context_processors.media" processor which does exactly
the same as your version.
--
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: context porcessors request.context media_url breaks admin

2010-06-29 Thread justin jools
Hi Tom if you read my original post you will realise that the error is
being caused by setting of context processors to media_url (see
original post).
When context processors are active the {media_url} tag works
perfectly, but breaks the admin.

If I comment out :
settings.py
#TEMPLATE_CONTEXT_PROCESSORS =
('portfolio.context_processors.media_url',)
and
urls.py
#from django.template import RequestContext

the admin then works.

I believe this has nothing to do with a template error, but some kind
of conflict. To satisfy mystic meg, I have included error with
traceback:

TemplateSyntaxError at /admin/
Caught an exception while rendering: userRequest Method: GET
Request URL: http://127.0.0.1:8000/admin/
Exception Type: TemplateSyntaxError
Exception Value: Caught an exception while rendering: user
Exception Location: C:\Python26\lib\site-packages\django\template
\debug.py in render_node, line 81
Python Executable: C:\Python26\python.exe
Python Version: 2.6.4
Python Path: ['c:\\django\\portfolio_root', 'C:\\Python26\\lib\\site-
packages\\html5lib-0.90-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
\django_page_cms-1.1.1-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
\django_cms-2.0.2-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
\django_admin_tools-0.2.0-py2.6.egg', 'C:\\Python26\\lib\\site-packages
\\django_friends-0.1.5-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
\django_schedule-0.1.0-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
\python_dateutil-1.5-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
\django_forum-r53-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
\django_notification-0.1.4-py2.6.egg', 'C:\\Python26\\lib\\site-
packages\\django_pagination-1.0.5-py2.6.egg', 'C:\\Python26\\lib\\site-
packages\\sphinx-0.6.5-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
\docutils-0.6-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
\jinja2-2.4.1-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
\pygments-1.3.1-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
\django_avatar-1.0.4-py2.6.egg', 'C:\\Python26\\lib\\site-packages\
\django_locations-0.1.0-py2.6.egg', 'C:\\Windows\\system32\
\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\
\Python26\\lib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\
\Python26', 'C:\\Python26\\lib\\site-packages', 'C:\\Python26\\lib\
\site-packages\\PIL', 'c:\\python26\\lib\\site-packages']
Server time: Tue, 29 Jun 2010 13:36:03 +0100

Template error
In template c:\python26\lib\site-packages\django\contrib\admin
\templates\admin\index.html, error at line 56

Caught an exception while rendering: user
46 {% endif %}

47 

48 {% endblock %}

49
50 {% block sidebar %}

51 

52 

53 {% trans 'Recent Actions' %}

54 {% trans 'My Actions' %}

55 {% load log %}

56 {% get_admin_log 10 as admin_log for_user user %}

57 {% if not admin_log %}

58 {% trans 'None available' %}

59 {% else %}

60 

61 {% for entry in admin_log %}

62 

63 {% if entry.is_deletion %}

64 {{ entry.object_repr }}

65 {% else %}

66 {{ entry.object_repr }}

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.1.1
Python Version: 2.6.4
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'django.contrib.markup',
 'portfolio']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Template error:
In template c:\python26\lib\site-packages\django\contrib\admin
\templates\admin\index.html, error at line 56
   Caught an exception while rendering: user
   46 : {% endif %}


   47 : 


   48 : {% endblock %}


   49 :


   50 : {% block sidebar %}


   51 : 


   52 : 


   53 : {% trans 'Recent Actions' %}


   54 : {% trans 'My Actions' %}


   55 : {% load log %}


   56 :  {% get_admin_log 10 as admin_log for_user user
%}


   57 : {% if not admin_log %}


   58 : {% trans 'None available' %}


   59 : {% else %}


   60 : 


   61 : {% for entry in admin_log %}


   62 : 


   63 : {% if entry.is_deletion %}


   64 : {{ entry.object_repr }}


   65 : {% else %}


   66 : {{ entry.object_repr }}


Traceback:
File "C:\Python26\lib\site-packages\django\core\handlers\base.py" in
get_response
  92. response = callback(request, *callback_args,
**callback_kwargs)
File "C:\Python26\lib\site-packages\django\contrib\admin\sites.py" in
wrapper
  196. return self.admin_view(view, cacheable)(*args,
**kwargs)
File "C:\Python26

Re: context porcessors request.context media_url breaks admin

2010-06-29 Thread Tom Evans
On Tue, Jun 29, 2010 at 12:33 PM, justin jools <justinjo...@gmail.com> wrote:
> I corrected my settings.py links:
>
> TEMPLATE_DIRS = 'C:/django/portfolio_root/templates/'
> MEDIA_ROOT = 'C:/django/portfolio_root/site-media/'
> MEDIA_URL = '/site-media/'
> ADMIN_MEDIA_PREFIX = '/media/'
>
> but I still get this error:
>
> TemplateSyntaxError at /admin/
> Caught an exception while rendering: userRequest Method: GET
> Request URL: http://127.0.0.1:8000/admin/
> Exception Type: TemplateSyntaxError
> Exception Value: Caught an exception while rendering: user
> Exception Location: C:\Python26\lib\site-packages\django\template
> \debug.py in render_node, line 81
> Python Executable: C:\Python26\python.exe
> Python Version: 2.6.4
>

All that says is that your template has an error. Mystic Meg is out to
lunch, you will have to supply better information.

Cheers

Tom

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: context porcessors request.context media_url breaks admin

2010-06-29 Thread justin jools
I corrected my settings.py links:

TEMPLATE_DIRS = 'C:/django/portfolio_root/templates/'
MEDIA_ROOT = 'C:/django/portfolio_root/site-media/'
MEDIA_URL = '/site-media/'
ADMIN_MEDIA_PREFIX = '/media/'

but I still get this error:

TemplateSyntaxError at /admin/
Caught an exception while rendering: userRequest Method: GET
Request URL: http://127.0.0.1:8000/admin/
Exception Type: TemplateSyntaxError
Exception Value: Caught an exception while rendering: user
Exception Location: C:\Python26\lib\site-packages\django\template
\debug.py in render_node, line 81
Python Executable: C:\Python26\python.exe
Python Version: 2.6.4

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: context porcessors request.context media_url breaks admin

2010-06-29 Thread justin jools
Yes I did accidentally set my

ADMIN_MEDIA_PREFIX = '/site-media/' instead of media

I'll try this

On Jun 29, 8:57 am, bruno desthuilliers
<bruno.desthuilli...@gmail.com> wrote:
> On 29 juin, 00:44, justin jools <justinjo...@gmail.com> wrote:
>
>
>
>
>
> > I am trying to use media_url with generic views:
> > When I set context processors to media_url, with generic views it
> > breaks Admin:
>
> > Caught an exception while rendering: user
>
> > settings.py
> > TEMPLATE_CONTEXT_PROCESSORS =
> > ('portfolio.context_processors.media_url',)
>
> > context_processors.py
> > def media_url(request):
> >     from django.conf import settings
> >     return {'media_url': settings.MEDIA_URL}
>
> > urls.py
> > from django.template import RequestContext
>
> > urlpatterns = patterns('',
> >     (r'^admin/', include(admin.site.urls)),
> >     (r'^work/$', 'django.views.generic.list_detail.object_list',
> > dict(info_dict, template_name="portfolio/projects_list.html")),
> > )
>
> > and when I remove it the admin works, but I have no media_url
> > reference
>
> > Any suggestions please?
>
> Check your MEDIA_URL and ADMIN_MEDIA_PREFIX settings, collisions can
> happen - like if your MEDIA_URL is '/medias/' and your
> ADMIN_MEDIA_PREFIX is '/medias/ too - that have this exact result.
> FWIW, you can set the ADMIN_MEDIA_PREFIX to whatever you want (I
> usually use '/admins-medias/' to avoid the above problem).
>
> HTH- Hide quoted text -
>
> - Show quoted text -

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: context porcessors request.context media_url breaks admin

2010-06-29 Thread bruno desthuilliers
On 29 juin, 00:44, justin jools <justinjo...@gmail.com> wrote:
> I am trying to use media_url with generic views:
> When I set context processors to media_url, with generic views it
> breaks Admin:
>
> Caught an exception while rendering: user
>
> settings.py
> TEMPLATE_CONTEXT_PROCESSORS =
> ('portfolio.context_processors.media_url',)
>
> context_processors.py
> def media_url(request):
>     from django.conf import settings
>     return {'media_url': settings.MEDIA_URL}
>
> urls.py
> from django.template import RequestContext
>
> urlpatterns = patterns('',
>     (r'^admin/', include(admin.site.urls)),
>     (r'^work/$', 'django.views.generic.list_detail.object_list',
> dict(info_dict, template_name="portfolio/projects_list.html")),
> )
>
> and when I remove it the admin works, but I have no media_url
> reference
>
> Any suggestions please?

Check your MEDIA_URL and ADMIN_MEDIA_PREFIX settings, collisions can
happen - like if your MEDIA_URL is '/medias/' and your
ADMIN_MEDIA_PREFIX is '/medias/ too - that have this exact result.
FWIW, you can set the ADMIN_MEDIA_PREFIX to whatever you want (I
usually use '/admins-medias/' to avoid the above problem).

HTH

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



context porcessors request.context media_url breaks admin

2010-06-28 Thread justin jools
I am trying to use media_url with generic views:
When I set context processors to media_url, with generic views it
breaks Admin:

Caught an exception while rendering: user

settings.py
TEMPLATE_CONTEXT_PROCESSORS =
('portfolio.context_processors.media_url',)

context_processors.py
def media_url(request):
from django.conf import settings
return {'media_url': settings.MEDIA_URL}

urls.py
from django.template import RequestContext

urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
(r'^work/$', 'django.views.generic.list_detail.object_list',
dict(info_dict, template_name="portfolio/projects_list.html")),
)

and when I remove it the admin works, but I have no media_url
reference

Any suggestions please?

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: Problem with static files (MEDIA_URL and MEDIA_ROOT)

2010-06-28 Thread nadae ivar badio
Hi do you speack french?

2010/6/27 Denis Ricardo <dnsrica...@gmail.com>

> Hello people! I am having any problems with static files (images, CSS)
> in Django. I configured the MEDIA_URL and MEDIA_ROOT in settings.py
> and when I execute the server and I go see the webpage, the static
> files doesn't are encountered (the page stay without anything).
>
> Screen Shot of my page: http://yfrog.com/jq35546894
>
> I am using the Django 1.1, on Ubuntu 10.04. The following are the
> server logs:
>
> http://dpaste.com/211961/
>
> This files exists! They are in this directory, but doesn't are
> encountered by the Django.
> The directory of my project follows below:
>
> http://dpaste.com/211962/
>
> And these are the files of project:
>
> settings.py: http://dpaste.com/211967/
>
> urls.py: http://dpaste.com/211964/
>
> views.py: http://dpaste.com/211969/
>
> base.html: http://dpaste.com/211971/ # This is the page of the Screen
> Shot
>
> Anybody can help me?
>
> (Sorry by my bad english.)
>
> --
> 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<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: Problem with static files (MEDIA_URL and MEDIA_ROOT)

2010-06-27 Thread Graham Dumpleton


On Jun 27, 10:53 pm, Denis Ricardo <dnsrica...@gmail.com> wrote:
> Hello people! I am having any problems with static files (images, CSS)
> in Django. I configured the MEDIA_URL and MEDIA_ROOT in settings.py
> and when I execute the server and I go see the webpage, the static
> files doesn't are encountered (the page stay without anything).
>
> Screen Shot of my page:http://yfrog.com/jq35546894
>
> I am using the Django 1.1, on Ubuntu 10.04. The following are the
> server logs:
>
> http://dpaste.com/211961/

The logs show:

  GET /home/denis/Aptana%20Studio%20Workspace/SMSPI/SMSPI/media/
estilo.css

This indicates you have specified a file system path in settings file
where a URL is expected.

In particular MEDIA_URL is set wrong.

Graham

> This files exists! They are in this directory, but doesn't are
> encountered by the Django.
> The directory of my project follows below:
>
> http://dpaste.com/211962/
>
> And these are the files of project:
>
> settings.py:http://dpaste.com/211967/
>
> urls.py:http://dpaste.com/211964/
>
> views.py:http://dpaste.com/211969/
>
> base.html:http://dpaste.com/211971/# This is the page of the Screen
> Shot
>
> Anybody can help me?
>
> (Sorry by my bad english.)

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Problem with static files (MEDIA_URL and MEDIA_ROOT)

2010-06-27 Thread Denis Ricardo
Hello people! I am having any problems with static files (images, CSS)
in Django. I configured the MEDIA_URL and MEDIA_ROOT in settings.py
and when I execute the server and I go see the webpage, the static
files doesn't are encountered (the page stay without anything).

Screen Shot of my page: http://yfrog.com/jq35546894

I am using the Django 1.1, on Ubuntu 10.04. The following are the
server logs:

http://dpaste.com/211961/

This files exists! They are in this directory, but doesn't are
encountered by the Django.
The directory of my project follows below:

http://dpaste.com/211962/

And these are the files of project:

settings.py: http://dpaste.com/211967/

urls.py: http://dpaste.com/211964/

views.py: http://dpaste.com/211969/

base.html: http://dpaste.com/211971/ # This is the page of the Screen
Shot

Anybody can help me?

(Sorry by my bad english.)

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: Using array of URLs for MEDIA_URL

2010-06-11 Thread Martin Siniawski
Alex,

Thanks for the answer.

I tried doing something like the first thing you proposed (MEDIA_URL
as a callable) but I had to tweak it a little bit because the template
wasn't calling the callable, but rather printing 'function
object .'.

What do you think of the solution I posted?

Best,
Martin

On Jun 8, 11:29 am, Alex Robbins <alexander.j.robb...@gmail.com>
wrote:
> I haven't tested this, but it seems like you could do it one of two
> ways:
>
> Define media root as a function in your settings.py. If you pass a
> callable to the template, it will be called.
> MEDIA_ROOTS = ['server1', 'server2', 'server3']
> def MEDIA_ROOT():
>     from random import choice
>     return choice(MEDIA_ROOTS)
>
> OR
>
> Use a context processor to add MEDIA_ROOTS to the context and use the
> random template tag.
>
> {{ MEDIA_ROOTS|random }}
>
> Steven's custom template tag works too.
>
> Alex
> On Jun 8, 7:32 am, Martin Siniawski <msi...@gmail.com> wrote:
>
>
>
> > Steve,
>
> > Thanks for the answer.
>
> > If I understand correctly your idea and code, each template would have
> > only one value for the MEDIA_URL (randomly chosen from the array),
> > right?
>
> > What I was looking for was a way of distributing the value of the
> > MEDIA_URL uniformly along the values of an array, in each template. So
> > in a certain template the MEDIA_URL would have more than one value.
> > Maybe if I set it as a callable (with the logic that choses the values
> > inside it) that would work.
>
> > I cannot quite understand why there isn't anymore people running into
> > this issue.
>
> > Best and thanks again for the answer,
> > Martin
>
> > On Jun 7, 10:46 am, Steven L Smith <ssmit...@naz.edu> wrote:
>
> > > Hi Martin-
>
> > > I don't know what the "official" answer would be, but you could write 
> > > your own
> > > context processor that had something like:
>
> > > from random import choice
> > > MEDIA_URLS =  'static1.site.com', 'static2.site.com', 'static3.site.com' ]
> > > def media(request):
> > >     return {'MEDIA_URL': choice(MEDIA_URLS)}
>
> > > Then, in settings.py, include your custom context processor instead of 
> > > the one
> > > built-in to to Django.
>
> > > -Steve
>
> > > 
> > > Steven L Smith, Web Developer
> > > Department of Information Technology Services
> > > Nazareth College of Rochester
> > > 585-389-2085   |   ssmit...@naz.eduhttp://www.naz.edu/pub/~ssmith46
> > > 

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: Using array of URLs for MEDIA_URL

2010-06-11 Thread Martin Siniawski
Steven and Alex,

This is what I coded, and tried it out and works. I still have to
benchmark it.

from django.conf import settings

class RoundRobinMediaUrl():
current_url = 0
try:
media_urls = settings.MEDIA_URLS
except:
media_urls = (settings.MEDIA_URL,)

def __unicode__(self):
self.current_url += 1
self.current_url %= len(self.media_urls)
return self.media_urls[self.current_url]

def context_proc (req):
return {'MEDIA_URL': RoundRobinMediaUrl()}

On Jun 11, 3:09 pm, Martin Siniawski <msi...@gmail.com> wrote:
> Steven,
>
> Thanks again for the answer.
>
> I couldn't quite understand the comment regarding the round robin
> server setup. In order to workaround the browser's limitations to
> simultaneous connections that can be opened to a host, the links to
> static content in the HTML content must be to different hosts. How
> would that be done with the round robin server setup you mentioned?
>
> Thanks for the proposed solution as well. It seems to be a good
> solution, but it would imply changing all the templates, and I don't
> even know what would happen to those templates that are from external
> apps.
>
> I'll post a solution that I coded on my own, though I haven't yet
> benchmarked it.
>
> Best,
> Martin
>
> On Jun 8, 11:01 am, Steven L Smith <ssmit...@naz.edu> wrote:
>
>
>
> > Looks like my email client screwed up the indentation I've added some
> > indents...
>
> > random_media.py
> > -
> > from django import template
> > from random import choice
>
> > register = template.Library()
>
> > defmedia_url():
> >     media_urls = ['site1.example.com', 'site2.example.com',
> > 'site3.example.com']
> >     return choice(media_urls)
> > register.simple_tag(media_url)
>
> > in some template
> > --
> > {% load random_media %}
> > {%media_url%}
>
> > 
> > Steven L Smith, Web Developer
> > Department of Information Technology Services
> > Nazareth College of Rochester
> > 585-389-2085 begin_of_the_skype_highlighting              585-389-2085      
> > end_of_the_skype_highlighting | 
> > ssmit...@naz.eduhttp://www.naz.edu/pub/~ssmith46
> > 

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: Using array of URLs for MEDIA_URL

2010-06-11 Thread Martin Siniawski
Steven,

Thanks again for the answer.

I couldn't quite understand the comment regarding the round robin
server setup. In order to workaround the browser's limitations to
simultaneous connections that can be opened to a host, the links to
static content in the HTML content must be to different hosts. How
would that be done with the round robin server setup you mentioned?

Thanks for the proposed solution as well. It seems to be a good
solution, but it would imply changing all the templates, and I don't
even know what would happen to those templates that are from external
apps.

I'll post a solution that I coded on my own, though I haven't yet
benchmarked it.

Best,
Martin

On Jun 8, 11:01 am, Steven L Smith <ssmit...@naz.edu> wrote:
> Looks like my email client screwed up the indentation I've added some
> indents...
>
> random_media.py
> -
> from django import template
> from random import choice
>
> register = template.Library()
>
> defmedia_url():
>     media_urls = ['site1.example.com', 'site2.example.com',
> 'site3.example.com']
>     return choice(media_urls)
> register.simple_tag(media_url)
>
> in some template
> --
> {% load random_media %}
> {%media_url%}
>
> 
> Steven L Smith, Web Developer
> Department of Information Technology Services
> Nazareth College of Rochester
> 585-389-2085 begin_of_the_skype_highlighting              585-389-2085      
> end_of_the_skype_highlighting | 
> ssmit...@naz.eduhttp://www.naz.edu/pub/~ssmith46
> 

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: Using array of URLs for MEDIA_URL

2010-06-08 Thread Alex Robbins
I haven't tested this, but it seems like you could do it one of two
ways:

Define media root as a function in your settings.py. If you pass a
callable to the template, it will be called.
MEDIA_ROOTS = ['server1', 'server2', 'server3']
def MEDIA_ROOT():
from random import choice
return choice(MEDIA_ROOTS)

OR

Use a context processor to add MEDIA_ROOTS to the context and use the
random template tag.

{{ MEDIA_ROOTS|random }}


Steven's custom template tag works too.

Alex
On Jun 8, 7:32 am, Martin Siniawski <msi...@gmail.com> wrote:
> Steve,
>
> Thanks for the answer.
>
> If I understand correctly your idea and code, each template would have
> only one value for the MEDIA_URL (randomly chosen from the array),
> right?
>
> What I was looking for was a way of distributing the value of the
> MEDIA_URL uniformly along the values of an array, in each template. So
> in a certain template the MEDIA_URL would have more than one value.
> Maybe if I set it as a callable (with the logic that choses the values
> inside it) that would work.
>
> I cannot quite understand why there isn't anymore people running into
> this issue.
>
> Best and thanks again for the answer,
> Martin
>
> On Jun 7, 10:46 am, Steven L Smith <ssmit...@naz.edu> wrote:
>
> > Hi Martin-
>
> > I don't know what the "official" answer would be, but you could write your 
> > own
> > context processor that had something like:
>
> > from random import choice
> > MEDIA_URLS =  'static1.site.com', 'static2.site.com', 'static3.site.com' ]
> > def media(request):
> >     return {'MEDIA_URL': choice(MEDIA_URLS)}
>
> > Then, in settings.py, include your custom context processor instead of the 
> > one
> > built-in to to Django.
>
> > -Steve
>
> > 
> > Steven L Smith, Web Developer
> > Department of Information Technology Services
> > Nazareth College of Rochester
> > 585-389-2085   |   ssmit...@naz.eduhttp://www.naz.edu/pub/~ssmith46
> > 

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: Using array of URLs for MEDIA_URL

2010-06-08 Thread Steven L Smith
Looks like my email client screwed up the indentation I've added some 
indents...

random_media.py
-
from django import template
from random import choice

register = template.Library()

def media_url():
media_urls = ['site1.example.com', 'site2.example.com', 
'site3.example.com']
return choice(media_urls)
register.simple_tag(media_url)


in some template
--
{% load random_media %}
{% media_url %}






Steven L Smith, Web Developer
Department of Information Technology Services
Nazareth College of Rochester
585-389-2085 begin_of_the_skype_highlighting  585-389-2085  
end_of_the_skype_highlighting | ssmit...@naz.edu
http://www.naz.edu/pub/~ssmith46


-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: Using array of URLs for MEDIA_URL

2010-06-08 Thread Steven L Smith
Hi Martin-

Yes, that is what that code would do... I guess I forgot about how context 
processors work. :-P

I think most people do this type of thing with a round-robin server setup. If 
you wanted to do it django-side, you'd probably need to do a template tag. 
Note the callable...

-Steve



random_media.py
-
from django import template
from random import choice

register = template.Library()

def media_url():
   media_urls = ['site1.example.com', 'site2.example.com', 
'site3.example.com']
   return choice(media_urls)
register.simple_tag(media_url)


in some template
--
{% load random_media %}
{% media_url %}






Steven L Smith, Web Developer
Department of Information Technology Services
Nazareth College of Rochester
585-389-2085   |   ssmit...@naz.edu
http://www.naz.edu/pub/~ssmith46


- Original Message -
From: "Martin Siniawski" <msi...@gmail.com>
To: "Django users" <django-users@googlegroups.com>
Sent: Tuesday, June 8, 2010 8:32:53 AM GMT -05:00 US/Canada Eastern
Subject: Re: Using array of URLs for MEDIA_URL

Steve,

Thanks for the answer.

If I understand correctly your idea and code, each template would have
only one value for the MEDIA_URL (randomly chosen from the array),
right?

What I was looking for was a way of distributing the value of the
MEDIA_URL uniformly along the values of an array, in each template. So
in a certain template the MEDIA_URL would have more than one value.
Maybe if I set it as a callable (with the logic that choses the values
inside it) that would work.

I cannot quite understand why there isn't anymore people running into
this issue.

Best and thanks again for the answer,
Martin

On Jun 7, 10:46 am, Steven L Smith <ssmit...@naz.edu> wrote:
> Hi Martin-
>
> I don't know what the "official" answer would be, but you could write your 
own
> context processor that had something like:
>
> from random import choice
> MEDIA_URLS =  'static1.site.com', 'static2.site.com', 'static3.site.com' ]
> def media(request):
> return {'MEDIA_URL': choice(MEDIA_URLS)}
>
> Then, in settings.py, include your custom context processor instead of the 
one
> built-in to to Django.
>
> -Steve
>
> 
> Steven L Smith, Web Developer
> Department of Information Technology Services
> Nazareth College of Rochester
> 585-389-2085   |   ssmit...@naz.eduhttp://www.naz.edu/pub/~ssmith46
> 

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: Using array of URLs for MEDIA_URL

2010-06-08 Thread Martin Siniawski
Steve,

Thanks for the answer.

If I understand correctly your idea and code, each template would have
only one value for the MEDIA_URL (randomly chosen from the array),
right?

What I was looking for was a way of distributing the value of the
MEDIA_URL uniformly along the values of an array, in each template. So
in a certain template the MEDIA_URL would have more than one value.
Maybe if I set it as a callable (with the logic that choses the values
inside it) that would work.

I cannot quite understand why there isn't anymore people running into
this issue.

Best and thanks again for the answer,
Martin

On Jun 7, 10:46 am, Steven L Smith <ssmit...@naz.edu> wrote:
> Hi Martin-
>
> I don't know what the "official" answer would be, but you could write your own
> context processor that had something like:
>
> from random import choice
> MEDIA_URLS =  'static1.site.com', 'static2.site.com', 'static3.site.com' ]
> def media(request):
>     return {'MEDIA_URL': choice(MEDIA_URLS)}
>
> Then, in settings.py, include your custom context processor instead of the one
> built-in to to Django.
>
> -Steve
>
> 
> Steven L Smith, Web Developer
> Department of Information Technology Services
> Nazareth College of Rochester
> 585-389-2085   |   ssmit...@naz.eduhttp://www.naz.edu/pub/~ssmith46
> 

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: Using array of URLs for MEDIA_URL

2010-06-07 Thread Steven L Smith
Hi Martin-

I don't know what the "official" answer would be, but you could write your own 
context processor that had something like:

from random import choice
MEDIA_URLS =  'static1.site.com', 'static2.site.com', 'static3.site.com' ]
def media(request):
    return {'MEDIA_URL': choice(MEDIA_URLS)}

Then, in settings.py, include your custom context processor instead of the one 
built-in to to Django.

-Steve




Steven L Smith, Web Developer
Department of Information Technology Services
Nazareth College of Rochester
585-389-2085   |   ssmit...@naz.edu
http://www.naz.edu/pub/~ssmith46


-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Using array of URLs for MEDIA_URL

2010-06-07 Thread Martin Siniawski
Hey guys,

I wanted to ask if there's any way or accepted solution for using more
than one URL simultaneously as the MEDIA_URL, so as to enable browsers
to further parallelize the download of static content. That is, having
something like:

MEDIA_URL = [ 'static1.site.com', 'static2.site.com',
'static3.site.com' ]

I've been searching through the group, documentation and online but
couldn't find anything that addressed the subject.

Thanks,
Martin

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



Re: MEDIA_URL is not pushed to templates

2010-03-15 Thread Bobby Roberts
ah... my media processor got shot somehow

On Mar 15, 7:51 pm, Bobby Roberts <tchend...@gmail.com> wrote:
> hi group... got a strange situation.  MEDIA_URL is not being pushed to
> the templates for some reason.
>
> In my settings file i have
>
> MEDIA_URL='/static/'
> ...
> TEMPLATE_CONTEXT_PROCESSORS=(
>    'django.core.context_processors.request',)
>
> and in the template i am specifying it as {{MEDIA_URL}}
>
> however there is no value for MEDIA_URL in the template.  What could I
> be missing?
>
> PS:  if i go directly to the file  /static/images/mypic.jpg, the image
> shows up fine

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



MEDIA_URL is not pushed to templates

2010-03-15 Thread Bobby Roberts
hi group... got a strange situation.  MEDIA_URL is not being pushed to
the templates for some reason.

In my settings file i have

MEDIA_URL='/static/'
...
TEMPLATE_CONTEXT_PROCESSORS=(
   'django.core.context_processors.request',)

and in the template i am specifying it as {{MEDIA_URL}}

however there is no value for MEDIA_URL in the template.  What could I
be missing?


PS:  if i go directly to the file  /static/images/mypic.jpg, the image
shows up fine

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.



media_url tute

2009-11-13 Thread Mike Dewhirst
I have looked at the django docs 
(http://docs.djangoproject.com/en/dev/topics/forms/media/) which 
painstakingly describe how to set up MEDIA_ROOT and MEDIA_URL.

Does anyone know of a tutorial or other docco which covers the topic?

Thanks

Mike

--

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 at 
http://groups.google.com/group/django-users?hl=.




Re: accessing media_url in javascript

2009-10-05 Thread Daniel Roseman

On Oct 5, 10:34 pm, "neri...@gmail.com" <neri...@gmail.com> wrote:
> I was interested in finding out how I would go about accessing django
> vars in my javascript file i.e., media_url within javascript. Do I
> need to use a serializer to achieve this?
>
> Thanks,
>
> Jason

Just put a script element in your Django template which defines a
global javascript variable for media_url. It probably makes sense to
do this in the base template that the others inherit from.


accessing media_url in javascript

2009-10-05 Thread neri...@gmail.com

I was interested in finding out how I would go about accessing django
vars in my javascript file i.e., media_url within javascript. Do I
need to use a serializer to achieve this?

Thanks,

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



Re: admin running in dev mode (manage.py runserver) ignores MEDIA_URL

2009-08-14 Thread physicsnick

You have to use the --adminmedia option to runserver; there's no other
way. Even if you serve the media yourself, the admin media overrides
your urls.py. The developers seem to have stopped listening to
complaints about fixing this:

http://code.djangoproject.com/ticket/8336



On Aug 14, 5:16 am, Aljosa Mohorovic <aljosa.mohoro...@gmail.com>
wrote:
> settings.py:
> MEDIA_ROOT = "%s/media" % PROJECT_ROOT # set to media folder in
> project root
> MEDIA_URL = '/media/'
> ADMIN_MEDIA_PREFIX = '/media/admin/'
>
> urls.py
> if settings.DEBUG:
>   urlpatterns += patterns('',
>     (r'^media/(?P.*)$', 'django.views.static.serve',
> {'document_root': settings.MEDIA_ROOT, 'show_indexes':True}),
>   )
>
> example:
> PROJECT_ROOT/media/admin/img/admin/default-bg.gif exists but
> PROJECT_ROOT/env/lib/python2.6/site-packages/django/contrib/admin/
> media/img/admin/default-bg.gif is used instead.
>
> when i use mod_wsgi to run this instead of manage.py runserver it
> works as expected.
>
> anybody knows how to force django admin when running in dev mode
> (manage.py runserver) to use images from MEDIA_URL and not images in
> django/contrib/admin/media?
>
> Aljosa Mohorovic
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



admin running in dev mode (manage.py runserver) ignores MEDIA_URL

2009-08-14 Thread Aljosa Mohorovic

settings.py:
MEDIA_ROOT = "%s/media" % PROJECT_ROOT # set to media folder in
project root
MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX = '/media/admin/'

urls.py
if settings.DEBUG:
  urlpatterns += patterns('',
(r'^media/(?P.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT, 'show_indexes':True}),
  )

example:
PROJECT_ROOT/media/admin/img/admin/default-bg.gif exists but
PROJECT_ROOT/env/lib/python2.6/site-packages/django/contrib/admin/
media/img/admin/default-bg.gif is used instead.

when i use mod_wsgi to run this instead of manage.py runserver it
works as expected.

anybody knows how to force django admin when running in dev mode
(manage.py runserver) to use images from MEDIA_URL and not images in
django/contrib/admin/media?

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



Re: MEDIA_URL MEDIA_ROOT

2009-07-30 Thread cootetom

If you are using the django development server whilst developing then
you can use django.views.static.serve to download static or media
files. You should not use this method in production however as it is
not considered stable. Just place this in your url.py file:

from settings import DEBUG, STATIC_DOC_ROOT, MEDIA_ROOT

if DEBUG:
urlpatterns += patterns('',
(r'^.*/?static/(?P.*)$', 'django.views.static.serve',
{'document_root': STATIC_DOC_ROOT}),
(r'^site_media/(?P.*)$', 'django.views.static.serve',
{'document_root': MEDIA_ROOT})
)

Then you can access static files from /static/path/to/file and you can
access your uploaded media using /site_media/path/to/file

You can of course use settings variables for the URL's as well as the
roots but that's upto you. Not sure why files aren't being put into
the /user_files/ directory that you have specified, they should be!


On Jul 30, 11:38 am, Salvatore Leone <salvatore.le...@isti.cnr.it>
wrote:
> Hi again,
>
> I have configured MEDIA_ROOT =
> '/home/testpec/public_html/pecwizard/uploads/' and the file uploads
> works fine, so in the 'uploads' directory there are all my uploaded files.
>
> Two questions:
>
> 1.
> in models.py I have the following:
>
> class Attach(models.Model):
>   attached_file = models.FileField(upload_to='user_files')
>   # other stuff
>
> why all of the files are stored in 'uploads' and not in
> 'uploads/user_files/'?
>
> 2.
> I can't download the files, probably I don't understand the MEDIA_URL
> parameter. Here it is:
> MEDIA_URL = 'http://localhost:8000/wiz/uploads/'
>
> but trying to access the files returns me a 404 error.
>
> I can workaround this configuring urls.py for serving static files. Is
> this the right way to do it??
>
> regards,
> Salvatore
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: MEDIA_URL MEDIA_ROOT

2009-07-30 Thread Xiong Chiamiov

On Jul 30, 3:38 am, Salvatore Leone <salvatore.le...@isti.cnr.it>
wrote:
> I can't download the files, probably I don't understand the MEDIA_URL
> parameter. Here it is:
> MEDIA_URL = 'http://localhost:8000/wiz/uploads/'
>
> but trying to access the files returns me a 404 error.

You shouldn't have to use MEDIA_URL at all for local development.  You
should be able to access anything located in the directory specified
by MEDIA_ROOT with /media/.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



MEDIA_URL MEDIA_ROOT

2009-07-30 Thread Salvatore Leone

Hi again,

I have configured MEDIA_ROOT = 
'/home/testpec/public_html/pecwizard/uploads/' and the file uploads 
works fine, so in the 'uploads' directory there are all my uploaded files.

Two questions:

1. 
in models.py I have the following:

class Attach(models.Model):
  attached_file = models.FileField(upload_to='user_files')
  # other stuff

why all of the files are stored in 'uploads' and not in 
'uploads/user_files/'?


2.
I can't download the files, probably I don't understand the MEDIA_URL 
parameter. Here it is:
MEDIA_URL = 'http://localhost:8000/wiz/uploads/'

but trying to access the files returns me a 404 error.

I can workaround this configuring urls.py for serving static files. Is 
this the right way to do it??


regards,
Salvatore

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



Re: MEDIA_URL and ADMIN_MEDIA_PREFIX

2009-07-12 Thread Sam Lai

Forgot to add - the usual trick is to symlink the admin media in your
MEDIA_URL; that way you don't have to set up two different aliases in
your web server config.

2009/7/13 Sam Lai <samuel@gmail.com>:
> Yes, because unless you copy the admin site's media over to your
> MEDIA_URL (or vice-versa), Django won't be able to find the admin
> media.
>
> From http://docs.djangoproject.com/en/dev/ref/settings/
>
> ADMIN_MEDIA_PREFIX
>
> Default: '/media/'
>
> The URL prefix for admin media -- CSS, JavaScript and images used by
> the Django administrative interface. Make sure to use a trailing
> slash, and to have this be different from the MEDIA_URL setting (since
> the same URL cannot be mapped onto two different sets of files).
>
> 2009/7/13 sjtirtha <sjtir...@gmail.com>:
>> Hi,
>>
>> I found out that MEDIA_URL and ADMIN_MEDIA_PREFIX may not have the same
>> value, otherwise images that is located in this MEDIA_URL cannot be
>> displayed in browser.
>> I did not found about this anywhere in the documentation. Is my assumption
>> correct?
>>
>> Regards,
>> Steve
>>
>> >>
>>
>

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



Re: MEDIA_URL and ADMIN_MEDIA_PREFIX

2009-07-12 Thread Sam Lai

Yes, because unless you copy the admin site's media over to your
MEDIA_URL (or vice-versa), Django won't be able to find the admin
media.

>From http://docs.djangoproject.com/en/dev/ref/settings/

ADMIN_MEDIA_PREFIX

Default: '/media/'

The URL prefix for admin media -- CSS, JavaScript and images used by
the Django administrative interface. Make sure to use a trailing
slash, and to have this be different from the MEDIA_URL setting (since
the same URL cannot be mapped onto two different sets of files).

2009/7/13 sjtirtha <sjtir...@gmail.com>:
> Hi,
>
> I found out that MEDIA_URL and ADMIN_MEDIA_PREFIX may not have the same
> value, otherwise images that is located in this MEDIA_URL cannot be
> displayed in browser.
> I did not found about this anywhere in the documentation. Is my assumption
> correct?
>
> Regards,
> Steve
>
> >
>

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



MEDIA_URL and ADMIN_MEDIA_PREFIX

2009-07-12 Thread sjtirtha
Hi,

I found out that MEDIA_URL and ADMIN_MEDIA_PREFIX may not have the same
value, otherwise images that is located in this MEDIA_URL cannot be
displayed in browser.
I did not found about this anywhere in the documentation. Is my assumption
correct?

Regards,
Steve

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



Re: How to use MEDIA_URL on flatpages content?

2009-06-25 Thread Panu Tangchalermkul

I think I got your concept, converting all MEDIA_URL to corresponding
url before displaying.
But I still curious to know where should I put this code in the
project?

I've been thinking and can only come up with a way, by creating a new
middleware replicating FlatpageFallbackMiddleware
but instead of calling a view in django.contrib, it will call my new
view that has been modified by your suggestion.

However, I don't like this method. It forces me to copy an entire
django's view, which i think it's not a future-proof.

Your suggestion?


On Jun 25, 4:41 pm, Rama Vadakattu <rama.vadaka...@gmail.com> wrote:
> Please ignore the last line..
>
> On Jun 25, 2:40 pm, Rama Vadakattu <rama.vadaka...@gmail.com> wrote:
>
> > you can put {{MEDIA_URL}}
>
> > but while displaying instead of displaying it directly  just do the
> > below
>
> > from django.template.loader import render_to_string
> > from django.template import Context, Template
>
> > t = Template("flat page content goes here")
> > newflatpage = t.render({},context_instance=RequestContext(request))
> > #above is the new flat page where media url are replaced by their
> > corresponding urls
>
> > subject = render_to_string('',{},RequestContext(request))
>
> > On Jun 25, 12:53 pm, Panu Tangchalermkul <pan...@gmail.com> wrote:
>
> > > In the content of my flatpage, there's a picture to be displayed that
> > > it was stored in django media folder. I want to link to this file
> > > without having to specify its url directly. Instead, I want to use
> > > something like {{MEDIA_URL}} when editing the content via django-
> > > admin. I know I can use it normally on flatpage template but how about
> > > on the content?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to use MEDIA_URL on flatpages content?

2009-06-25 Thread Rama Vadakattu

Please ignore the last line..

On Jun 25, 2:40 pm, Rama Vadakattu <rama.vadaka...@gmail.com> wrote:
> you can put {{MEDIA_URL}}
>
> but while displaying instead of displaying it directly  just do the
> below
>
> from django.template.loader import render_to_string
> from django.template import Context, Template
>
> t = Template("flat page content goes here")
> newflatpage = t.render({},context_instance=RequestContext(request))
> #above is the new flat page where media url are replaced by their
> corresponding urls
>
> subject = render_to_string('',{},RequestContext(request))
>
> On Jun 25, 12:53 pm, Panu Tangchalermkul <pan...@gmail.com> wrote:
>
> > In the content of my flatpage, there's a picture to be displayed that
> > it was stored in django media folder. I want to link to this file
> > without having to specify its url directly. Instead, I want to use
> > something like {{MEDIA_URL}} when editing the content via django-
> > admin. I know I can use it normally on flatpage template but how about
> > on the content?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to use MEDIA_URL on flatpages content?

2009-06-25 Thread Rama Vadakattu

you can put {{MEDIA_URL}}

but while displaying instead of displaying it directly  just do the
below

from django.template.loader import render_to_string
from django.template import Context, Template

t = Template("flat page content goes here")
newflatpage = t.render({},context_instance=RequestContext(request))
#above is the new flat page where media url are replaced by their
corresponding urls



subject = render_to_string('',{},RequestContext(request))



On Jun 25, 12:53 pm, Panu Tangchalermkul <pan...@gmail.com> wrote:
> In the content of my flatpage, there's a picture to be displayed that
> it was stored in django media folder. I want to link to this file
> without having to specify its url directly. Instead, I want to use
> something like {{MEDIA_URL}} when editing the content via django-
> admin. I know I can use it normally on flatpage template but how about
> on the content?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How to use MEDIA_URL on flatpages content?

2009-06-25 Thread Panu Tangchalermkul

In the content of my flatpage, there's a picture to be displayed that
it was stored in django media folder. I want to link to this file
without having to specify its url directly. Instead, I want to use
something like {{MEDIA_URL}} when editing the content via django-
admin. I know I can use it normally on flatpage template but how about
on the content?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: MEDIA_ROOT, MEDIA_URL and upload_to confusion (~.~)

2009-01-16 Thread DragonSlayre

Yeah, that makes good sense - I tried finding out info on
djangoproject but didn't quite understand what they were for.

Thanks

On Jan 17, 7:04 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:
> On Fri, 2009-01-16 at 21:06 -0800, DragonSlayre wrote:
> > I'm using django-thumbs (http://code.google.com/p/django-thumbs/) to
> > create some thumbnails for my site:
>
> > class Image(models.Model):
> >     title = models.CharField(max_length=50, blank=True, null=True)
> >     caption = models.CharField(max_length=100, blank=True, null=True)
> >     photo = ImageWithThumbsField(
> >             upload_to="site_images",
> >             sizes=((270,150),))
>
> > And in my settings my media path is as following:
>
> > MEDIA_ROOT = os.path.abspath(os.path.join(PROJECT_DIR, 'site_media'))
> > MEDIA_URL = 'static/'
>
> > I'm trying to upload my images into the  'site_media/static/
> > site_images/' location
>
> > When I upload however, it puts the image into 'site_media/
> > site_images/'
> > The strange thing though, is that the location that gets stored in the
> > database is 'static/site_images/imageName.jpg'
>
> > I'm really not sure what's going on, and feel completely confused.
>
> The MEDIA_ROOT is the path on the storage system (the hard-drive,
> typically) where the data is saved.
>
> The MEDIA_URL is the URL used by the web browser to access the media. It
> is entirely unrelated to the location on the hard-drive. Even though
> URLs and directory paths both use '/' as a separator, they don't refer
> to the same namespace of objects. The web browser requesting the media
> is using a URL and has absolutely no idea where you might have chosen to
> store the data on the disk.
>
> However (and this is an important point), to make things a little
> simpler on the code developer, when you're using the straightforward
> file-saving operations, as you are doing, Django makes the filesystem
> layout underneath MEDIA_ROOT match the URL space layout referred to by
> URL_ROOT.
>
> I'm not familiar with the django-thumbs project, so I have no idea why
> it's putting the MEDIA_URL portion on the front of the filename it
> saves. What I will mention, though, is that Django's normal ImageField
> model field only stores "site_images/imageName.jpg" in the case you
> describe. So a template might put MEDIA_URL on the front of that to get
> the URL and something wanting to access the file directory (a cronjob or
> something similar) would prepend MEDIA_ROOT to the name in the database.
>
> Does that clear things up a bit? MEDIA_URL is the URL used by external
> things like web browsers to access the object. MEDIA_ROOT talks about
> where the image is stored on disk. They are unrelated concepts (in the
> sense that URLs are not file paths), although you would normally have to
> configure your webserver so that requests for MEDIA_URL were served by
> files under MEDIA_ROOT.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: MEDIA_ROOT, MEDIA_URL and upload_to confusion (~.~)

2009-01-16 Thread Malcolm Tredinnick

On Fri, 2009-01-16 at 21:06 -0800, DragonSlayre wrote:
> I'm using django-thumbs (http://code.google.com/p/django-thumbs/) to
> create some thumbnails for my site:
> 
> class Image(models.Model):
> title = models.CharField(max_length=50, blank=True, null=True)
> caption = models.CharField(max_length=100, blank=True, null=True)
> photo = ImageWithThumbsField(
> upload_to="site_images",
> sizes=((270,150),))
> 
> And in my settings my media path is as following:
> 
> MEDIA_ROOT = os.path.abspath(os.path.join(PROJECT_DIR, 'site_media'))
> MEDIA_URL = 'static/'
> 
> I'm trying to upload my images into the  'site_media/static/
> site_images/' location
> 
> When I upload however, it puts the image into 'site_media/
> site_images/'
> The strange thing though, is that the location that gets stored in the
> database is 'static/site_images/imageName.jpg'
> 
> I'm really not sure what's going on, and feel completely confused.

The MEDIA_ROOT is the path on the storage system (the hard-drive,
typically) where the data is saved.

The MEDIA_URL is the URL used by the web browser to access the media. It
is entirely unrelated to the location on the hard-drive. Even though
URLs and directory paths both use '/' as a separator, they don't refer
to the same namespace of objects. The web browser requesting the media
is using a URL and has absolutely no idea where you might have chosen to
store the data on the disk.

However (and this is an important point), to make things a little
simpler on the code developer, when you're using the straightforward
file-saving operations, as you are doing, Django makes the filesystem
layout underneath MEDIA_ROOT match the URL space layout referred to by
URL_ROOT.

I'm not familiar with the django-thumbs project, so I have no idea why
it's putting the MEDIA_URL portion on the front of the filename it
saves. What I will mention, though, is that Django's normal ImageField
model field only stores "site_images/imageName.jpg" in the case you
describe. So a template might put MEDIA_URL on the front of that to get
the URL and something wanting to access the file directory (a cronjob or
something similar) would prepend MEDIA_ROOT to the name in the database.

Does that clear things up a bit? MEDIA_URL is the URL used by external
things like web browsers to access the object. MEDIA_ROOT talks about
where the image is stored on disk. They are unrelated concepts (in the
sense that URLs are not file paths), although you would normally have to
configure your webserver so that requests for MEDIA_URL were served by
files under MEDIA_ROOT.

Regards,
Malcolm



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



Re: MEDIA_ROOT, MEDIA_URL and upload_to confusion (~.~)

2009-01-16 Thread DragonSlayre

Ok, I got it working, I changed:

> photo = ImageWithThumbsField(
> upload_to="site_images",
> sizes=((270,150),))

to:

 photo = ImageWithThumbsField(
 upload_to="static/site_images",
 sizes=((270,150),))

and

> MEDIA_URL = 'static/'

to:

 MEDIA_URL = '/site_media/'

I think I get it now - the media_root is where django uploads images
to, and the media_url is where the images will be linked from. -
hopefully that is what they mean :)


On Jan 17, 6:06 pm, DragonSlayre <lssay...@gmail.com> wrote:
> I'm using django-thumbs (http://code.google.com/p/django-thumbs/) to
> create some thumbnails for my site:
>
> class Image(models.Model):
>     title = models.CharField(max_length=50, blank=True, null=True)
>     caption = models.CharField(max_length=100, blank=True, null=True)
>     photo = ImageWithThumbsField(
>             upload_to="site_images",
>             sizes=((270,150),))
>
> And in my settings my media path is as following:
>
> MEDIA_ROOT = os.path.abspath(os.path.join(PROJECT_DIR, 'site_media'))
> MEDIA_URL = 'static/'
>
> I'm trying to upload my images into the  'site_media/static/
> site_images/' location
>
> When I upload however, it puts the image into 'site_media/
> site_images/'
> The strange thing though, is that the location that gets stored in the
> database is 'static/site_images/imageName.jpg'
>
> I'm really not sure what's going on, and feel completely confused.
>
> Any help will be greatly appreciated!
>
> Louis
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



MEDIA_ROOT, MEDIA_URL and upload_to confusion (~.~)

2009-01-16 Thread DragonSlayre

I'm using django-thumbs (http://code.google.com/p/django-thumbs/) to
create some thumbnails for my site:

class Image(models.Model):
title = models.CharField(max_length=50, blank=True, null=True)
caption = models.CharField(max_length=100, blank=True, null=True)
photo = ImageWithThumbsField(
upload_to="site_images",
sizes=((270,150),))

And in my settings my media path is as following:

MEDIA_ROOT = os.path.abspath(os.path.join(PROJECT_DIR, 'site_media'))
MEDIA_URL = 'static/'

I'm trying to upload my images into the  'site_media/static/
site_images/' location

When I upload however, it puts the image into 'site_media/
site_images/'
The strange thing though, is that the location that gets stored in the
database is 'static/site_images/imageName.jpg'

I'm really not sure what's going on, and feel completely confused.

Any help will be greatly appreciated!


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



Re: to understand MEDIA_URL

2009-01-05 Thread Alan
Thanks Mark for your reply.

On Mon, Jan 5, 2009 at 14:25, Mark Jones <mark0...@gmail.com> wrote:

>
> Are you closing the file after you write to it and before you try to
> send it?


Pretty sure about it. In fact, after try and error I found out that
restarting the server and my static folder gets refreshed and aware of this
particular file and code works.


> Why do you have to write it to a file to deliver it as a
> static file, why not just render it to a response directly?


But it was like that, however, the file content I want to show is 'report',
without extension, so mimetype is unknown for most browsers, so instead of
showing the content, it prompted for download (which I don't want). If I
could only set the mimetype to 'text/html', but then I couldn't find a way
then reading the content and rendering with  using a view and
template.


> On Jan 5, 4:13 am, Alan <alanwil...@gmail.com> wrote:
> > Hi List,
> > Because I couldn't find any idea better I am using "MEDIA_URL =
> '/static/'"
> > as a repository for the output of my application so I can see the results
> in
> > the web interface and download them.
> >
> > However, I noticed for a particular case where I open and read a file
> > content to be viewed in a web page that I get this error:
> >
> > -
> > IOError at /ccpngrid/call_status_func
> >
> > [Errno 2] No such file or directory:
> >
> '/Users/alan/workspace/webapps/static/grid/alan_20090105T094321/static/grid/alan_20090105T093444/Results_1brv_ccpngrid/DOCS/last_it/report'
> >
> > Request Method: POST
> > Request URL:http://localhost:8000/ccpngrid/call_status_func
> > Exception Type: IOError
> > Exception Value:
> >
> > [Errno 2] No such file or directory:
> >
> '/Users/alan/workspace/webapps/static/grid/alan_20090105T094321/static/grid/alan_20090105T093444/Results_1brv_ccpngrid/DOCS/last_it/report'
> >
> > Exception Location: /Users/alan/workspace/webapps/src/webAppsRoutines.py
> in
> > callStatusFunc, line 518
> > -
> >
> > If I stop and restart the sever (manager.py runserver) it seems that my
> > static folder gets refreshed and then the server is now aware of this
> > 'report' file and then I can see it. If during this runserver session, I
> > submit another job, the new report will failed as show above.
> >
> > So, is it possible to "refresh" my "MEDIA_URL = '/static/'" in runserver
> > session without needing to restart it, or better rethink all the way I
> did
> > for presenting results (not using "MEDIA_URL = '/static/'" basically)?
> > Suggestions are welcome.
> >
> > Many thanks in advance.
> >
> > Alan
> >
> > --
> > Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
> > Department of Biochemistry, University of Cambridge.
> > 80 Tennis Court Road, Cambridge CB2 1GA, UK.
> >
> > >>http://www.bio.cam.ac.uk/~awd28<<
> >
>


-- 
Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
Department of Biochemistry, University of Cambridge.
80 Tennis Court Road, Cambridge CB2 1GA, UK.
>>http://www.bio.cam.ac.uk/~awd28<<

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



Re: to understand MEDIA_URL

2009-01-05 Thread Mark Jones

Are you closing the file after you write to it and before you try to
send it?  Why do you have to write it to a file to deliver it as a
static file, why not just render it to a response directly?

On Jan 5, 4:13 am, Alan <alanwil...@gmail.com> wrote:
> Hi List,
> Because I couldn't find any idea better I am using "MEDIA_URL = '/static/'"
> as a repository for the output of my application so I can see the results in
> the web interface and download them.
>
> However, I noticed for a particular case where I open and read a file
> content to be viewed in a web page that I get this error:
>
> -
> IOError at /ccpngrid/call_status_func
>
> [Errno 2] No such file or directory:
> '/Users/alan/workspace/webapps/static/grid/alan_20090105T094321/static/grid/alan_20090105T093444/Results_1brv_ccpngrid/DOCS/last_it/report'
>
> Request Method: POST
> Request URL:http://localhost:8000/ccpngrid/call_status_func
> Exception Type: IOError
> Exception Value:
>
> [Errno 2] No such file or directory:
> '/Users/alan/workspace/webapps/static/grid/alan_20090105T094321/static/grid/alan_20090105T093444/Results_1brv_ccpngrid/DOCS/last_it/report'
>
> Exception Location: /Users/alan/workspace/webapps/src/webAppsRoutines.py in
> callStatusFunc, line 518
> -
>
> If I stop and restart the sever (manager.py runserver) it seems that my
> static folder gets refreshed and then the server is now aware of this
> 'report' file and then I can see it. If during this runserver session, I
> submit another job, the new report will failed as show above.
>
> So, is it possible to "refresh" my "MEDIA_URL = '/static/'" in runserver
> session without needing to restart it, or better rethink all the way I did
> for presenting results (not using "MEDIA_URL = '/static/'" basically)?
> Suggestions are welcome.
>
> Many thanks in advance.
>
> Alan
>
> --
> Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
> Department of Biochemistry, University of Cambridge.
> 80 Tennis Court Road, Cambridge CB2 1GA, UK.
>
> >>http://www.bio.cam.ac.uk/~awd28<<
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



to understand MEDIA_URL

2009-01-05 Thread Alan
Hi List,
Because I couldn't find any idea better I am using "MEDIA_URL = '/static/'"
as a repository for the output of my application so I can see the results in
the web interface and download them.

However, I noticed for a particular case where I open and read a file
content to be viewed in a web page that I get this error:

-
IOError at /ccpngrid/call_status_func

[Errno 2] No such file or directory:
'/Users/alan/workspace/webapps/static/grid/alan_20090105T094321/static/grid/alan_20090105T093444/Results_1brv_ccpngrid/DOCS/last_it/report'

Request Method: POST
Request URL: http://localhost:8000/ccpngrid/call_status_func
Exception Type: IOError
Exception Value:

[Errno 2] No such file or directory:
'/Users/alan/workspace/webapps/static/grid/alan_20090105T094321/static/grid/alan_20090105T093444/Results_1brv_ccpngrid/DOCS/last_it/report'

Exception Location: /Users/alan/workspace/webapps/src/webAppsRoutines.py in
callStatusFunc, line 518
-

If I stop and restart the sever (manager.py runserver) it seems that my
static folder gets refreshed and then the server is now aware of this
'report' file and then I can see it. If during this runserver session, I
submit another job, the new report will failed as show above.

So, is it possible to "refresh" my "MEDIA_URL = '/static/'" in runserver
session without needing to restart it, or better rethink all the way I did
for presenting results (not using "MEDIA_URL = '/static/'" basically)?
Suggestions are welcome.

Many thanks in advance.

Alan

-- 
Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
Department of Biochemistry, University of Cambridge.
80 Tennis Court Road, Cambridge CB2 1GA, UK.
>>http://www.bio.cam.ac.uk/~awd28<<

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



Re: specifying MEDIA_URL in CSS files

2008-09-19 Thread Erik Allik

I still can't understand why you can use relative URLs to images in  
your CSS files. If you keep your CSS files together with your image  
files, nothing will break if you move them to another URL.

Sorry if I'm missing something obvious.

Erik

On 18.09.2008, at 20:56, MrJogo wrote:

>
> Erik: I can't use relative URLs because of how my hosting service (my
> university) is set up. Each account is at something like
> www.university.edu/~studentname/. I could hard code it if I were
> leaving it on my space, but I'm making it for a group (which has space
> at www.university.edu/group/groupname/), and when I move it over, I'd
> like to have to go through and change as little as possible.
>
> Tim: I'll look into those solutions.
>
> Thanks to both of you.
>
> On Sep 13, 4:12 pm, Tim Chase <[EMAIL PROTECTED]> wrote:
>>> What's the best way to use MEDIA_URL in a CSS file. For example,  
>>> right
>>> now my CSS file has something like:
>>
>>> body {
>>>   background: transparent url('/media/images/bg.gif') repeat;
>>> }
>>
>>> I would like to use MEDIA_URL instead of /media/ (in a number of
>>> places), but other than that the file is static. What's the best way
>>> to do this? Should I templatize the whole thing? What type of a
>>> performance change will I see (approximately)?
>>
>> This changes your CSS file from being static to being dynamic.
>> As such, Django should serve the file.  However, as it's not
>> something you'd expect to change often, Django's caching
>> framework (making use of, say, memcached) may prove enormously
>> helpful.  Alternatively, you might be able to hook into the
>> post_syncdb signal, and use it to write/put the render the
>> dynamic CSS file into a static CSS file on the static-media server.
>>
>> Just a few ideas,
>>
>> -tim
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: specifying MEDIA_URL in CSS files

2008-09-18 Thread MrJogo

Erik: I can't use relative URLs because of how my hosting service (my
university) is set up. Each account is at something like
www.university.edu/~studentname/. I could hard code it if I were
leaving it on my space, but I'm making it for a group (which has space
at www.university.edu/group/groupname/), and when I move it over, I'd
like to have to go through and change as little as possible.

Tim: I'll look into those solutions.

Thanks to both of you.

On Sep 13, 4:12 pm, Tim Chase <[EMAIL PROTECTED]> wrote:
> > What's the best way to use MEDIA_URL in a CSS file. For example, right
> > now my CSS file has something like:
>
> > body {
> >   background: transparent url('/media/images/bg.gif') repeat;
> > }
>
> > I would like to use MEDIA_URL instead of /media/ (in a number of
> > places), but other than that the file is static. What's the best way
> > to do this? Should I templatize the whole thing? What type of a
> > performance change will I see (approximately)?
>
> This changes your CSS file from being static to being dynamic.
> As such, Django should serve the file.  However, as it's not
> something you'd expect to change often, Django's caching
> framework (making use of, say, memcached) may prove enormously
> helpful.  Alternatively, you might be able to hook into the
> post_syncdb signal, and use it to write/put the render the
> dynamic CSS file into a static CSS file on the static-media server.
>
> Just a few ideas,
>
> -tim
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: specifying MEDIA_URL in CSS files

2008-09-13 Thread Tim Chase

> What's the best way to use MEDIA_URL in a CSS file. For example, right
> now my CSS file has something like:
> 
> body {
>   background: transparent url('/media/images/bg.gif') repeat;
> }
> 
> I would like to use MEDIA_URL instead of /media/ (in a number of
> places), but other than that the file is static. What's the best way
> to do this? Should I templatize the whole thing? What type of a
> performance change will I see (approximately)?

This changes your CSS file from being static to being dynamic. 
As such, Django should serve the file.  However, as it's not 
something you'd expect to change often, Django's caching 
framework (making use of, say, memcached) may prove enormously 
helpful.  Alternatively, you might be able to hook into the 
post_syncdb signal, and use it to write/put the render the 
dynamic CSS file into a static CSS file on the static-media server.

Just a few ideas,

-tim







--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: specifying MEDIA_URL in CSS files

2008-09-13 Thread Erik Allik

You should instead simply use relative URLs to images in CSS files.  
Style sheets and images are (normally) always at the same location  
relative to each other so nothing will break if you change their  
location. Of course if your images are in a different domain than your  
style sheets, that's another case.

Erik


On 14.09.2008, at 1:56, MrJogo wrote:

>
> What's the best way to use MEDIA_URL in a CSS file. For example, right
> now my CSS file has something like:
>
> body {
>  background: transparent url('/media/images/bg.gif') repeat;
> }
>
> I would like to use MEDIA_URL instead of /media/ (in a number of
> places), but other than that the file is static. What's the best way
> to do this? Should I templatize the whole thing? What type of a
> performance change will I see (approximately)?
>
> Thanks.
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



specifying MEDIA_URL in CSS files

2008-09-13 Thread MrJogo

What's the best way to use MEDIA_URL in a CSS file. For example, right
now my CSS file has something like:

body {
  background: transparent url('/media/images/bg.gif') repeat;
}

I would like to use MEDIA_URL instead of /media/ (in a number of
places), but other than that the file is static. What's the best way
to do this? Should I templatize the whole thing? What type of a
performance change will I see (approximately)?

Thanks.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



View not passing MEDIA_URL to Template

2008-09-04 Thread Cortland Klein

I have two templates, one called via a Generic View and one via my own  
View. They both extend a base.html view that has {{MEDIA_URL}} in it.

When the generic view is hit, the base.html template gets it's value, 
http://rtdev.apple.com/media/ 
  , but when my own View hits MEDIA_URL blanks.

I tried to get MEDIA_URL in my views.py to pass it in to my  
render_to_response but it seems from there that global isn't defined.

views.py:
> from django.shortcuts import render_to_response, get_object_or_404
>
> from models import Event
>
> def results(request):
>   event = get_object_or_404(Event, pk=request.REQUEST['event'])
>   response = {}
>   response['correct_answers'] = 0
>   response['total_questions'] = 0
>   response['passed'] = 0
>   response['name'] = request.REQUEST['name']
>   
>   # ...
>
>   return render_to_response('whatsnew/results.html', response)


-- 
Cortland Klein <[EMAIL PROTECTED]> +1 408 506 9791
http://pixelcort.com/
2260 California Street #13
Mountain View, CA, USA 94040

Alumni, Business Management <[EMAIL PROTECTED]>
San José State University

Alumni Technical Advisor, Entrepreneurial Society <[EMAIL PROTECTED] 
 >
http://e-society.org/

Q Techie, Silicon Valley Mac User Group
http://svmug.org/

Member, Silicon Valley Google Technology User Group
http://sv-gtug.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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: {{ media_url }}

2008-06-05 Thread Andrew Ingram

If you're using render_to_response you'll want to do something like this:

return render_to_response('my_template.html',
   my_data_dictionary,
   context_instance=RequestContext(request))

The last bit is the important part, it creates context data from the processors 
based on the request object.

- Andrew

chris hendrix wrote:
> Hi andrew.  I've got the
> from django.template import Context, Template line at the top of the view.
>
> How do i pass the media template contact processor to the template?
>
>
> BR
>
> On Thu, Jun 5, 2008 at 4:20 PM, Andrew Ingram <[EMAIL PROTECTED] 
> > wrote:
>
>
> Chances are that one of the views isn't passing the media template
> context processor to the template.
>
> = Andrew
>
> Bobby Roberts wrote:
> > i've got two templates in the same directory.  My css works fine on
> > one template but not the other.  My link to the css is
> >
> >   
> >
> > Can you think of any reason it would work fine for one template and
> > not the other when the templates are in the same dir?
> >
> >
> >
> > BR 
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: {{ media_url }}

2008-06-05 Thread chris hendrix
hi Aaron -

my template includes this link to the css



my view is:

from django import http
from forms import ziplookup
from django.shortcuts import get_object_or_404, render_to_response
from django.template import RequestContext
from django.template import Context, Template



def process_ziplookup(request):
if request.method=='POST':
form = ziplookup(request.POST)
if form.is_valid():
zipcode=request.POST.get('zipcode','')
return_ziplookup(zipcode)
else:
form = ziplookup()
return render_to_response ("upsratelookup.html",{'form':form})

def return_ziplookup(zipcode):
zip=zipcode
#assert False, zip
return render_to_response("upsratelookup.html",{'zipcode':zip})



thanks in advance for any help


BR
On Thu, Jun 5, 2008 at 5:20 PM, Aaron Fay <[EMAIL PROTECTED]> wrote:

>
> Hi Bobby,
>
> If you are referring to the media url that should be available via the
> context processor, then the variable in your template should be:
> {{ MEDIA_URL }}
>
> Unless you specifically are defining 'media_url' in your view.
>
> Hth,
> Aaron
>
> Bobby Roberts wrote:
> > i've got two templates in the same directory.  My css works fine on
> > one template but not the other.  My link to the css is
> >
> >   
> >
> > Can you think of any reason it would work fine for one template and
> > not the other when the templates are in the same dir?
> >
> >
> >
> > BR
> > >
> >
> >
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: {{ media_url }}

2008-06-05 Thread chris hendrix
Hi andrew.  I've got the
from django.template import Context, Template line at the top of the view.

How do i pass the media template contact processor to the template?


BR

On Thu, Jun 5, 2008 at 4:20 PM, Andrew Ingram <[EMAIL PROTECTED]> wrote:

>
> Chances are that one of the views isn't passing the media template
> context processor to the template.
>
> = Andrew
>
> Bobby Roberts wrote:
> > i've got two templates in the same directory.  My css works fine on
> > one template but not the other.  My link to the css is
> >
> >   
> >
> > Can you think of any reason it would work fine for one template and
> > not the other when the templates are in the same dir?
> >
> >
> >
> > BR
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: {{ media_url }}

2008-06-05 Thread Andrew Ingram

Chances are that one of the views isn't passing the media template 
context processor to the template.

= Andrew

Bobby Roberts wrote:
> i've got two templates in the same directory.  My css works fine on
> one template but not the other.  My link to the css is
>
>   
>
> Can you think of any reason it would work fine for one template and
> not the other when the templates are in the same dir?
>
>
>
> BR

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: {{ media_url }}

2008-06-05 Thread Aaron Fay

Hi Bobby,

If you are referring to the media url that should be available via the 
context processor, then the variable in your template should be:
{{ MEDIA_URL }}

Unless you specifically are defining 'media_url' in your view.

Hth,
Aaron

Bobby Roberts wrote:
> i've got two templates in the same directory.  My css works fine on
> one template but not the other.  My link to the css is
>
>   
>
> Can you think of any reason it would work fine for one template and
> not the other when the templates are in the same dir?
>
>
>
> BR
> >
>
>   

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



{{ media_url }}

2008-06-05 Thread Bobby Roberts

i've got two templates in the same directory.  My css works fine on
one template but not the other.  My link to the css is

  

Can you think of any reason it would work fine for one template and
not the other when the templates are in the same dir?



BR
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField get_X_url() method not respecting MEDIA_URL?

2008-06-04 Thread chris . czub

Thanks, that was it.

-Chris

On Jun 3, 5:44 pm, "Marty Alchin" <[EMAIL PROTECTED]> wrote:
> On Tue, Jun 3, 2008 at 5:15 PM, Chris Czub <[EMAIL PROTECTED]> wrote:
> > # URL that handles the media served from MEDIA_ROOT.
> > # Example: "http://media.lawrence.com;
> > MEDIA_URL = 'http://www.mysite.com/media'
>
> > which is correct - the url of the image SHOULD be
>
> >http://www.mysite.com/media/uploads/20080603151319/rrbk.jpg
>
> Unfortunately, that's not correct. Your MEDIA_URL setting needs a
> trailing slash in order for Python's urljoin() method to realize that
> it's a directory that needs to stay, not just a file that should be
> replaced. Change it to 'http://www.mysite.com/media/'and you should
> be fine.
>
> More recent (from just over a year ago) checkouts of Django have an
> additional comment added into the default settings.py to outline this
> more clearly.
>
> # URL that handles the media served from MEDIA_ROOT. Make sure to use a
> # trailing slash if there is a path component (optional in other cases).
> # Examples: "http://media.lawrence.com;, "http://example.com/media/;
>
> -Gul
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ImageField get_X_url() method not respecting MEDIA_URL?

2008-06-03 Thread Marty Alchin

On Tue, Jun 3, 2008 at 5:15 PM, Chris Czub <[EMAIL PROTECTED]> wrote:
> # URL that handles the media served from MEDIA_ROOT.
> # Example: "http://media.lawrence.com;
> MEDIA_URL = 'http://www.mysite.com/media'
>
>
> which is correct - the url of the image SHOULD be
>
> http://www.mysite.com/media/uploads/20080603151319/rrbk.jpg

Unfortunately, that's not correct. Your MEDIA_URL setting needs a
trailing slash in order for Python's urljoin() method to realize that
it's a directory that needs to stay, not just a file that should be
replaced. Change it to 'http://www.mysite.com/media/' and you should
be fine.

More recent (from just over a year ago) checkouts of Django have an
additional comment added into the default settings.py to outline this
more clearly.

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com;, "http://example.com/media/;

-Gul

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



ImageField get_X_url() method not respecting MEDIA_URL?

2008-06-03 Thread Chris Czub
I'm having an issue with the ImageField's get_X_url() method(I think it
actually inherits from FileField) not using my MEDIA_URL in the url it
forms.

*Model:*

class ImageUpload(models.Model):
image = models.ImageField(help_text='Image to upload',
upload_to="uploads/%Y%m%d%H%M%S")

class ImageUploadForm(ModelForm):
class Meta:
model = ImageUpload
def clean_image(self):
if self.cleaned_data.get('image'):
image_data = self.cleaned_data['image']

if not image_data:
raise forms.ValidationError('Please upload an image')
size = len(image_data.content)
if size > 1024000:
raise forms.ValidationError('Filesize too large. Expected <=
1 megabyte')
return image_data

If I call "get_image_url()" on an instance of a ImageUpload model that I
have called save_image_file on, I get the resultant url:

http://www.mysite.com/uploads/20080603151319/rrbk.jpg


However, my settings.py contains the settings:

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = '/home/myuser/webapps/static/'

# URL that handles the media served from MEDIA_ROOT.
# Example: "http://media.lawrence.com;
MEDIA_URL = 'http://www.mysite.com/media'


which is correct - the url of the image SHOULD be

http://www.mysite.com/media/uploads/20080603151319/rrbk.jpg


Any ideas?


-Chris Czub

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: MEDIA_URL doesnt work

2008-02-22 Thread Justin Lilly
You should def. read those articles. A quick fix (if you're in a time
crunch) is to add this to your base urls.py inserting the proper values:


if settings.DEBUG:
urlpatterns += patterns('',
(r'^my_sites_media_folder/(?P.*)$', 'django.views.static.serve',
{'document_root': '/path/to/my/media/folder'}),
)

which would allow you to go to
http://localhost:8000/my_sites_media_folder/ and serve static files
out of /path/to/my/media/folder.

again.. you should still read the articles to figure out WHY this works.

-justin

On Fri, Feb 22, 2008 at 3:19 PM, Pete Crosier <[EMAIL PROTECTED]>
wrote:

>
> Have a look at the links below, I think you're over-estimating what
> MEDIA_URL does for you -
> http://www.djangoproject.com/documentation/static_files/
> http://www.djangoproject.com/documentation/settings/#media-url
>
> On Feb 22, 7:54 pm, troeten <[EMAIL PROTECTED]> wrote:
> > Hi,
> > i have a problem with the MEDIA_URL in django.
> > My settings.py section looks like this:
> >
> > # Absolute path to the directory that holds media.
> > # Example: "/home/media/media.lawrence.com/"
> > MEDIA_ROOT = '/Users/stefan/Development/ju_amerang/media/'
> >
> > # URL that handles the media served from MEDIA_ROOT.
> > # Example: "http://media.lawrence.com;
> > MEDIA_URL = 'http://127.0.0.1:8000/media/'
> >
> > but, when i want to go tohttp://127.0.0.1:8000/media/with my browser
> > i get every time a 404 Error with the following message:
> > Using the URLconf defined in ju_amerang.urls, Django tried these URL
> > patterns, in this order:
> > ^mitglieder/
> > ^admin/
> > The current URL, /media/, didn't match any of these.
> >
> > can anyone help me?
> >
> > sorry for my bad englisch, but i hope you understand my
> >
> > regards stefan
> >
>


-- 
Justin Lilly
Web Developer

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



  1   2   >