Re: how to get the variable in the context

2012-04-28 Thread Amao Zhao
Dear DanYun Liu
Django has the biuld-in middlewar with the user.
You can use the user in your templates immediately.

在 2012年4月28日星期六,DanYun Liu 写道:

> I defined a context processor to pass the login user info to the template.
> and, I also need to use it in the view.
>
> is there any way to get the variable from the context?
>
> --
> Pursuit the freedom of the soul.
>
> --
> 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 'django-users@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-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: request.is_ajax() not working

2012-04-22 Thread Amao Zhao
dear psychok7:
You have no data from your ajax post, you should post some data with
your ajax post, like this
$.post("api/newdoc/", {'user':'your username'}, function(data) {
alert(data);
});
}

在 2012年4月23日星期一,psychok7 写道:

> hi there i am trying a simple example using AJAX, DJANGO, JQUERY, JSON and
> my if request.is_ajax() is not working for some reason.. here is my code:
>
> URLS: (r'api/newdoc/$', 'rose_miracle.views.newdoc'),
>
> VIEW:
> def newdoc(request):
> # only process POST request
> print "entrei"
> if request.is_ajax():
> print "entrei2" _#this is not working
> data= dict(request.POST)
> print data
> # save data to db
>
> return HttpResponse(simplejson.dumps([True]))
>
> return HttpResponse(simplejson.dumps([False]))
>
> js:
> $(document).ready(function(){
>
>
> alert("ya");
> $.post("api/newdoc/", function(data) {
> alert(data);
> });
> }
>
>
> i added this in a file as well, dont know how it works though
> https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax
>
> the print in my request.is_ajax()  is now working, what im i doing wrong??
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/J9sGcOB5wBwJ.
> To post to this group, send email to 
> django-users@googlegroups.com 'django-users@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-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: Django-cms plugins - ImportError no module named: cmsplugin_filer_file....

2012-03-04 Thread Amao Zhao
the APP_INSTALLS in your settings.py is a list. please recheck your 'filer'
and so no.
在 2012-3-4 下午10:07,"doniyor" 写道:

> Hi there,
>
> i need your help, i am trying to setup cms of my webpage, but
> everytime i run the "python manage.py syncdb" the error comes:
> django.core.exceptions.ImproperlyConfigured: ImportError filer
> cmsplugin_filer_image : no module named filer
> cmsplugin_filer_image
>
>
> i have installed all possible django-cms plugins, i have django 1.3.1
> running and python 2.7.
>
> why is this error, as a result i dont have a available plugins in
> cmspage to select.
>
> please help me, is it a django version problem ?
>
> this is my settings.py:
>
> http://pastebin.com/K0VaK62K
>
> thanks alot..
>
> --
> 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: How to create unique tags based on Taggit

2011-10-27 Thread Amao Zhao
hi, Tsung:
your code
for i in range(0,len(tags)):
   if tags[i] not in s:
   s.append(tags[i])
the tags[i] will return the tag.__unicode__() function and compare with the
s List, so you will get the complete List as the beginning. If you want get
your hope result, you can use the django core function:distinct().
Hope this can help you.

2011/10/27 Tsung-Hsien 

> I use Taggit to create a list of tags, and want to create unique tags
> of the list.
> I have a list as below
> tags=[[], [], [], [],
> [],[], [], []]
>
> and write this
> for i in range(0,len(tags)):
>if tags[i] not in s:
>s.append(tags[i])
>
> However, the output s is same as tags.
>
> s=[[], [], [], [],
> [],[], [], []]
>
> How to get s=[[], [], [], [ weather>]]
>
> 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
> 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: how to use "{% url *** %}" in django template file?

2011-08-07 Thread Amao Zhao
hi, jimmy
  you should pass the name of your func with url in template. such as your
example,
in your urls.py, you update the url: url(r'card/create$',
'card.views.create_card', name = 'create_card'),
and then you can use the url in your template like this :  {% url
create_card %}

在 2011年8月7日星期日,Jimmy  写道:
> Hi,
>
> I got the error "Caught ImportError while rendering: No module named
> urls" when using:
>
> {% url 'card.views.create_card' %} in the template file
>
> in the urls.py the route to the url is:
>
> urlpatterns = patterns('',
>   url(r'card/create$', 'card.views.create_card'),
> )
>
> The Django version I use is 1.3
>
> May I know what did I miss in setting?
>
> --
> 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: Django can't see my static files

2011-08-04 Thread Amao Zhao
Hi, you should conform the django.contrib.staticfiles in your
INSTALLED_APPS, then add the prefix to your template:{% load static %},

On Thursday, August 4, 2011, Guillaume Chorn 
wrote:
> Hi All,
>
> It's been a couple of days since I last wrote and no response so I'm
trying again (see below).  Please help if you can; without being able to
link to external static files I really can't do anything else with my site.
CSS is the very least of my concerns--worst case I can include that info in
each HTML file--but I need to be able to use some basic javascript for my
site and right now, because of this issue, I can't even do that.  Is there
anyone who could help me troubleshoot this?  Anyone??
>
> thanks,
> Guillaume
>
> On Wed, Aug 3, 2011 at 12:20 PM, Guillaume Chorn 
wrote:
>
> Ok, so I did use quotes in my link, and I changed my STATIC_URL setting
(in settings.py) from '/static/' to 'http://127.0.0.1:8000/static/' (I am
currently using the built-in development server at this address), but still
no luck.
>
> I'm not sure exactly what you mean by my "staticfiles settings."  (Sorry,
once again I'm a total beginner so please bear with me.)  My current
settings related to static files in 'settings.py' are as follows:
>
> STATIC_ROOT = ''
> STATIC_URL = 'http://127.0.0.1:8000/static/'
> ADMIN_MEDIA_PREFIX = '/static/admin/'
> STATICFILES_DIRS =
('/Users/guillaumechorn/Documents/website/mainapp/static')
> STATICFILES_FINDERS = (
> 'django.contrib.staticfiles.finders.FileSystemFinder',
> 'django.contrib.staticfiles.finders.AppDirectoriesFinder'
> )
>
> Below are the full contents of my urls.py file:
>
> from django.conf.urls.defaults import *
> from django.contrib.staticfiles.urls import staticfiles_urlpatterns
> from django.contrib import admin
> admin.autodiscover()
>
> urlpatterns = patterns('',
> (r'^home/$','mainapp.views.homepage'),
> (r'^mainapp/$','mainapp.views.index'),
> (r'^mainapp/(?P\d+)/$', 'mainapp.views.detail'),
> (r'^products/$','mainapp.views.productindex'),
> (r'^products/(?P\d+)/$','mainapp.views.productdetail'),
> (r'^news/$','mainapp.views.news'),
> (r'^events/(?P\d+)/$','mainapp.views.eventdetail'),
> (r'^partners/$','mainapp.views.partners'),
> (r'^admin/', include(admin.site.urls)),
> )
> urlpatterns += staticfiles_urlpatterns()
>
> Once again, I'm using the following to link to my CSS file:
>
> 
>
> Am I still missing something?  Did I enter in anything incorrectly?
>
> thanks,
> Guillaume
>
> On Tue, Aug 2, 2011 at 6:06 PM, Thomas Orozco 
wrote:
>
> Last thing, I made a typo, the address you could use should start with
http, like: http://127.0.0.1/static/
>
> Le 2 août 2011 12:01, "Thomas Orozco"  a
écrit :
>> A little detail, but you never know: you should put some ' ' in your
link.
>> Like this :
>>
>> 
>>
>>
>> If there are spaces in your path, this could cause the lookup to fail.
>>
>> And even if that's not the case, don't rely on the user's browser to fix
>> coding mistakes.
>> Le 2 août 2011 10:28, "Guillaume Chorn"  a
écrit :
>>> Thomas and Lokesh,
>>>
>>> Thanks very much for your help. I've modified the link in my HTML file
to
>>> be:
>>>
>>> >> />
>>>
>>> where "stylesheet" is the name of the CSS file, and this file is located
>>> inside the directory listed under STATIC_DIRS in my settings.py file. As
>>> mentioned in my prior email, I also already have STATIC_URL = '/static/'
>> in
>>> my settings.py file, and I have the correct methods listed under
>>> STATICFILES_FINDERS.
>>>
>>> But it is still not working. Do I have a syntax error somewhere? Or am I
>>> still missing something in another file?
>>>
>>

-- 
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: acces lists by index

2011-03-10 Thread Amao Zhao
django do not sport list[-n] index!

On Thu, Mar 10, 2011 at 11:24 PM, Szabo, Patrick (LNG-VIE) <
patrick.sz...@lexisnexis.at> wrote:

>  Hi,
>
>
>
> I’m trying to acces the last index of a list in my template but list[-1]
> throws  the following error:
>
>
>
> *Could not parse the remainder: '[-1]' from 'list[-1]'*
>
>
>
> How can i do it right !?
>
>
>
> Kind regards
>
>
>
>  . . . . . . . . . . . . . . . . . . . . . . . . . .
>
>  **
>
> Patrick Szabo
> XSLT Developer
>
> LexisNexis
> Marxergasse 25, 1030 Wien
>
> 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.
>

-- 
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.



Add Tiny_mce for Django Admin site

2010-12-02 Thread Amao Zhao
Hi all:
I am using Django1.2.3 and python2.6.5. And I want to add the Tiny_mce
for my admin in my project. But I followed the doc on
django,
it does not work. Here is my code:

The admin.py:

class EntryAdmin(admin.ModelAdmin):
class Media:
js = ('static/js/jquery.js',
  'static/js/tiny_mce/tiny_mce.js',
  'static/js/textarea.js',)

And I posted the js files in my project path.
The other hand, i added the following code in my urls.py

(r'^media/(?P.*)$','django.views.static.serve',{'document_root':settings.MEDIA_ROOT}),

But it did not work! Anyone can help me? Thanks!
Cheers for any clues

AmaoZhao

-- 
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: Automatic form submission and CSRF??

2010-09-26 Thread Amao Zhao
Hi, I think you should add the 'django.middleware.csrf.CsrfResponseMiddleware'
into your MIDDLEWARE_CLASSES in the settings model.

Yours,
BR

On Mon, Sep 27, 2010 at 7:58 AM, Russell Keith-Magee <
russ...@keith-magee.com> wrote:

> On Mon, Sep 27, 2010 at 12:18 AM, Joakim Hove 
> wrote:
> > Hello,
> >
> > I have a simple form which has method POST. When I view the form in
> > the browser and fill it normally everything works fine. However; the
> > plan is to submit this form automagically from a client program - I
> > have currently tried with the Python script:
> >
> > #!/usr/bin/python
> > import urllib
> > params = urllib.urlencode({"passwd": "Hemmelig",
> >   "user_id" : 1000,
> >   "subject" : "Tema",
> >   "extra_addr" : "joakim-h...@gmail.com",
> >   "date_list" : "10-10-2010",
> >   "body" : "Lang melding"})
> >
> > f = urllib.urlopen(form_url , params)
> > print f.read()
> >
> > The server just returns error code 403: "No CSRF or session cookie";
> > how can I get around this? Do I have to create a csrfmiddlewaretoken
> > on the client (which will not even have Python installed)?
>
> If it's impractical or impossible to get access to the CSRF token by
> GET before POSTing, you can disable CSRF on that single view. See [1]
> for details.
>
> [1] http://docs.djangoproject.com/en/dev/ref/contrib/csrf/#exceptions
>
> Yours,
> Russ Magee %-)
>
> --
> 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.