Re: Confusion about Static Files

2013-04-01 Thread yakoub abaya
it is very simple and doesn't require a separate http server like nginx 
first you configure in settings.py the variables STATIC_ROOT and 
STATIC_URL, then configure http server accordingly 
STATIC_ROOT is the absolute path in filesystem that stores your static 
files, you can put that inside django project itself if it is convenient 
and then in apache use Alias and Directory accordingly

STATIC_ROOT = '/srv/django/static_files'
STATIC_URL = '/django_static/'
then in apache :
ALias /django_static/ /srv/django/static_files/

  Require all granted


On Friday, March 29, 2013 10:36:30 PM UTC+3, David Pitchford wrote:
>
> I am experienced with Python but new to Django and web development in 
> general. I am struggling to understand its static files system from the 
> documentation . 
> It seems like I have to set multiple settings variables and create multiple 
> folders in order to get the server to accomplish the simple task of 
> "finding" these files. After toying with it for a few hours I haven't been 
> able to get the static files system to work and and have resorted to the 
> following system which is probably a very bad idea:
>
> In views.py:
>
> from django.http import HttpResponse
> from django.shortcuts import render_to_response
> from django.template import RequestContext
> import datetime
> import os.path
> import settings
>
> statictypes = {".css": "text/css",
>".js": "text/javascript"}
>
> def servestatic(request, filename):
> fullfilename = os.path.join(settings.STATIC_ROOT, filename)
> ext = os.path.splitext(filename)[1]
> return HttpResponse(open(fullfilename).read(), 
> content_type=statictypes[ext])
>
> And in urls.py:
>
> from django.conf.urls import patterns, include, url
> import mysite.views as views
>
> staticextensions = [ext[1:] for ext in views.statictypes.keys()]
> staticextstring = '|'.join(staticextensions)
>
> urlpatterns = patterns('',
> ...
> (r"([^/]+\.(?:%s))$" % staticextstring, views.servestatic)
> )
>
> This actually works (and I could optimize it by caching the static file 
> contents in memory rather than continually rereading them), but of course 
> it's circumventing Django's built-in system for managing static files. My 
> project architecture looks like this:
>
> mysite
> |
> |--manage.py
> |--mysite
>|
>|__init__.py
>|settings.py
>|urls.py
>|views.py
>|wgsi.py
>|--static
>|  |
>|  |--jquery.js
>|  |--TestFormat.css
>|
>|--templates
>   |
>   |--TestTemplate.html
>
> At the beginning, the documentation page mentions, "For small projects, 
> this isn’t a big deal, because you can just keep the static files somewhere 
> your web server can find it." This sounds like the simple solution I'm 
> looking for; what does it mean and how do I do it? I'm also frequently 
> confused by how when I created the project it created two nested folders 
> with the same name. Which is considered to be the "project root"?
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




template composition

2013-04-01 Thread yakoub abaya
i read about template inheritance and think it is great
but there is the possibility of including one template output as context 
variable for another template
for example :
*
c = new RequestContest()
c['navigation'] = render_to_string('navigation.html', {'links': links})

output = render_to_response('page.html', {}, c)

*and then in page.html :
*

 {{ navigation }} 
 ... 



*so my question is would this method break cache or damage performance or 
some other problem ?

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: comment templates

2013-02-21 Thread yakoub abaya

thank you, so this means enabling the comment app will not render comments 
anywhere
and developer needs to manually choose to include it in page templates

On Thursday, February 21, 2013 11:54:34 AM UTC+2, psjinx wrote:
>
> Hey,
>
> From Django Docs (
> https://docs.djangoproject.com/en/1.4/ref/contrib/comments/#quickly-rendering-a-comment-list
> )
>
> The easiest way to display a list of comments for some object is by using 
> render_comment_list<https://docs.djangoproject.com/en/1.4/ref/contrib/comments/#std:templatetag-render_comment_list>
> :
>  
> {% render_comment_list for [object] %}
>
> For example:
>
> {% render_comment_list for event %}
>
> This will render comments using a template named comments/list.html, a 
> default version of which is included with Django.
>
> Sincerely,
> Pankaj Singh
> http://about.me/psjinx
>
>
> On Thu, Feb 21, 2013 at 3:22 PM, yakoub abaya 
> <yakoub...@gmail.com
> > wrote:
>
>> can someone please explain where and how this template :
>> django/contrib/comments/templates/comments/list.html
>> gets rendered into the main page html template ? 
>>
>> -- 
>> 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?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




comment templates

2013-02-21 Thread yakoub abaya
can someone please explain where and how this template :
django/contrib/comments/templates/comments/list.html
gets rendered into the main page html template ?

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: form media (css+js)

2013-02-20 Thread yakoub abaya


On Wednesday, February 20, 2013 11:51:38 AM UTC+2, Tom Evans wrote:
>
> On Tue, Feb 19, 2013 at 9:07 PM, yakoub abaya 
> <yakoub...@gmail.com> 
> wrote: 
> > i read this page : 
> https://docs.djangoproject.com/en/1.4/topics/forms/media 
> > but i don't understand how those files gets rendered into the page 
> template 
> > is it our responsibility when creating template files to make sure those 
> > form media files gets rendered ? 
> > 
> > if we take django/contrib/admin/templates/admin/base.html for example, 
> > then i don't see under head where it happens, maybe {% block extrastyle 
> %}{% 
> > endblock %} ? 
> > 
>
> The form has an attribute called media. It is your responsibility to 
> output the value of that in the appropriate place in the page. 
>
> In the admin site, it has additional media to add, so it collects 
> form.media and the other media together in a list in the view, and 
> outputs it as the context variable media in the template. In 1.4, this 
> is here: 
>
> django/contrib/admin/options.py:985 
> django/contrib/admin/templates/admin/change_form.html:9 
>
> and probably in other places in the admin too - that is just an 
> example from the change form. 
>
> Cheers 
>
> Tom 
>
thanks a lot, django is wonderful but i think specifically regarding static 
files that drupal does it better :
in drupal you can add css+js anywhere in your code and not worry about 
including it in template
http://api.drupal.org/api/drupal/includes!common.inc/function/drupal_add_css/7
http://api.drupal.org/api/drupal/includes!theme.inc/function/template_process_html/7

 

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




form media (css+js)

2013-02-19 Thread yakoub abaya
i read this page : https://docs.djangoproject.com/en/1.4/topics/forms/media
but i don't understand how those files gets rendered into the page template
is it our responsibility when creating template files to make sure those 
form media files gets rendered ?

if we take django/contrib/admin/templates/admin/base.html for example, 
then i don't see under head where it happens, maybe {% block extrastyle 
%}{% endblock %} ?

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.