Re: Question mark in Django URL Mapping
On 27.1.2012 4:15, Chen Xu wrote: When I type the following as the normal python function, it returns the correct things: >>> pattern = re.compile(r'^account_activation\?user_id=(?P[0-9]+)_key=(?P[0-9a-zA-Z]+)$') >>> match = pattern.match("account_activation?user_id=36_key=f9717d96aa4e3452a47955225a60862d07119702") >>> match.groupdict() {'auth_key': 'f9717d96aa4e3452a47955225a60862d07119702', 'user_id': '36'} However, when I do this in the Django URL mapping: url(r'^account_activation?user_id=(?P[0-9]+)_key=(?P[0-9a-zA-Z]+)$', 'activate_registration'), It seems like the question mark is causing the url mapping not found issue. Does anyone know why. Django URL mapping parses only path part of the url. Query string part (part after question mark) are not parsed by url parser but passed in request GET dictionary. More information in https://docs.djangoproject.com/en/1.3/topics/http/urls/#what-the-urlconf-searches-against -- Jani Tiainen -- 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.
Question mark in Django URL Mapping
When I type the following as the normal python function, it returns the correct things: >>> pattern = re.compile(r'^account_activation\?user_id=(?P[0-9]+)_key=(?P[0-9a-zA-Z]+)$') >>> match = pattern.match("account_activation?user_id=36_key=f9717d96aa4e3452a47955225a60862d07119702") >>> match.groupdict() {'auth_key': 'f9717d96aa4e3452a47955225a60862d07119702', 'user_id': '36'} However, when I do this in the Django URL mapping: url(r'^account_activation?user_id=(?P[0-9]+)_key=(?P[0-9a-zA-Z]+)$', 'activate_registration'), It seems like the question mark is causing the url mapping not found issue. Does anyone know why. Thanks very much Best regards -- ⚡ Chen Xu ⚡ -- 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: MySQL limit sub-query problem
Works! Great! thanks!!! Lazy querysets! On Thu, Jan 26, 2012 at 12:32 PM, Alasdair Nicolwrote: > Hi RJ, > > > On 26/01/12 20:10, rahul jain wrote: >> >> All, >> >> I have a query. Its working fine on sqlite server but not working fine >> on mysql server. >> >> This is the error message on mysql server: "This version of MySQL >> doesn't yet support 'LIMIT& IN/ALL/ANY/SOME subquery" >> >> >> This is the query: >> >> inner_q = obj_unassigned.values_list('pk', flat=True)[:diff] >> total_objects = (obj_assigned | obj_class.objects.filter(pk__in=inner_q)) >> >> Any help appreciated on how to fix this. >> >> Thanks. >> >> RJ >> > > You can prevent the error by using `list()` to fetch the inner queryset in a > separate query: > > total_objects = (obj_assigned | > obj_class.objects.filter(pk__in=list(inner_q))) > > Alasdair > > -- > Alasdair Nicol > Developer, MEMSET > > mail: alasd...@memset.com > web: http://www.memset.com/ > > Memset Ltd., registration number 4504980. 25 Frederick Sanger Road, > Guildford, Surrey, GU2 7YD, UK. > > -- > 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 do you pass dissimilar data from view to template?
Brett, Thanks. That is what I needed. BillB1951 On Jan 26, 4:55 pm, Brett Eppswrote: > It sounds like you're confused about how to add more than one piece of > information to a template. When you render a template, the template is > given a context, which is a Python dict object. A dict is a bunch of > key-value pairs. So, right now, you're probably doing something like: > > return render_to_response('path/to/template.html', {'items': items}) > > Where items is a list of item objects. You can simply add more key-value > pairs to the dict to add your counts: > > items_25_to_50_count = Item.objects.filter(price__gte=25, > price__lte=50).count() > return render_to_response('path/to/template.html', > {'items': items, 'items_25_to_50_count': items_25_to_50_count}) > > Hopefully this helps with your question. > > Brett > > On 1/26/12 3:12 PM, "BillB1951" wrote: > > > > > > > > >I am a relatively new to Django, and have just run into a wall, but I > >am sure this will be a cake walk for you veterans out there. I have a > >list of items I am displaying in a table in a template. That is no > >problem I create an object (list of values) in my view send it to the > >template and render the table. However, I would like to also show on > >my template a bunch of count()¹s displayed as links, that when clicked > >will further filter the list of items displayed. For example, I may > >have items in the list that cost between $25 and $50, my link would > >show that there are say 20 items that match that criteria. When the > >link is selected in sends a request to the url.py that in turn > >executes a view that further filters the queryset then renders > >template again. > > >How do I get the count() info to the template? I do not think I can > >send two separate lists (objects) to the template (at least I have not > >been able to figure out how yet). I think I need to get the counts at > >the view and then somehow append them to my list object, but I¹m not > >sure how to do that and also, not quite sure how to parse those values > >in the template. I want the counts to show separate from the table > >generated from my list object, and I am somewhat concerned I¹m going > >to mess up my table that is working fine now. > > >I would appreciate any suggestions you have about how to tackle this, > >and I would really appreciate code examples because I am still > >somewhat Python/Django code challenged. > > >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 do you pass dissimilar data from view to template?
It sounds like you're confused about how to add more than one piece of information to a template. When you render a template, the template is given a context, which is a Python dict object. A dict is a bunch of key-value pairs. So, right now, you're probably doing something like: return render_to_response('path/to/template.html', {'items': items}) Where items is a list of item objects. You can simply add more key-value pairs to the dict to add your counts: items_25_to_50_count = Item.objects.filter(price__gte=25, price__lte=50).count() return render_to_response('path/to/template.html', {'items': items, 'items_25_to_50_count': items_25_to_50_count}) Hopefully this helps with your question. Brett On 1/26/12 3:12 PM, "BillB1951"wrote: >I am a relatively new to Django, and have just run into a wall, but I >am sure this will be a cake walk for you veterans out there. I have a >list of items I am displaying in a table in a template. That is no >problem I create an object (list of values) in my view send it to the >template and render the table. However, I would like to also show on >my template a bunch of count()¹s displayed as links, that when clicked >will further filter the list of items displayed. For example, I may >have items in the list that cost between $25 and $50, my link would >show that there are say 20 items that match that criteria. When the >link is selected in sends a request to the url.py that in turn >executes a view that further filters the queryset then renders >template again. > >How do I get the count() info to the template? I do not think I can >send two separate lists (objects) to the template (at least I have not >been able to figure out how yet). I think I need to get the counts at >the view and then somehow append them to my list object, but I¹m not >sure how to do that and also, not quite sure how to parse those values >in the template. I want the counts to show separate from the table >generated from my list object, and I am somewhat concerned I¹m going >to mess up my table that is working fine now. > >I would appreciate any suggestions you have about how to tackle this, >and I would really appreciate code examples because I am still >somewhat Python/Django code challenged. > >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.
How do you pass dissimilar data from view to template?
I am a relatively new to Django, and have just run into a wall, but I am sure this will be a cake walk for you veterans out there. I have a list of items I am displaying in a table in a template. That is no problem I create an object (list of values) in my view send it to the template and render the table. However, I would like to also show on my template a bunch of count()’s displayed as links, that when clicked will further filter the list of items displayed. For example, I may have items in the list that cost between $25 and $50, my link would show that there are say 20 items that match that criteria. When the link is selected in sends a request to the url.py that in turn executes a view that further filters the queryset then renders template again. How do I get the count() info to the template? I do not think I can send two separate lists (objects) to the template (at least I have not been able to figure out how yet). I think I need to get the counts at the view and then somehow append them to my list object, but I’m not sure how to do that and also, not quite sure how to parse those values in the template. I want the counts to show separate from the table generated from my list object, and I am somewhat concerned I’m going to mess up my table that is working fine now. I would appreciate any suggestions you have about how to tackle this, and I would really appreciate code examples because I am still somewhat Python/Django code challenged. 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.
Re: MySQL limit sub-query problem
Hi RJ, On 26/01/12 20:10, rahul jain wrote: All, I have a query. Its working fine on sqlite server but not working fine on mysql server. This is the error message on mysql server: "This version of MySQL doesn't yet support 'LIMIT& IN/ALL/ANY/SOME subquery" This is the query: inner_q = obj_unassigned.values_list('pk', flat=True)[:diff] total_objects = (obj_assigned | obj_class.objects.filter(pk__in=inner_q)) Any help appreciated on how to fix this. Thanks. RJ You can prevent the error by using `list()` to fetch the inner queryset in a separate query: total_objects = (obj_assigned | obj_class.objects.filter(pk__in=list(inner_q))) Alasdair -- Alasdair Nicol Developer, MEMSET mail: alasd...@memset.com web: http://www.memset.com/ Memset Ltd., registration number 4504980. 25 Frederick Sanger Road, Guildford, Surrey, GU2 7YD, UK. -- 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 (or other) templates for untrusted users?
I think that depends upon the context the view provides, and upon what tag libraries can be loaded. Objects in the context can have their methods called (with some restrictions). If your view pre-converts all interesting data to strings and numbers, and/or sequences or dictionaries of such, then the available methods are limited so you can review them for safety. You could also automate checking of any tag libraries loaded against a list of those you have deemed safe. Of course, there could be additional vulnerabilities that aren't coming to mind. Bill On 1/26/12, graemewrote: > Are Django templates safe enough to use templates provided by > untrusted users? Is it possible to limit functionality? I am not only > concerned with what the templates can access, but also things like > being able to consume excessive resources with, for example, deeply > nested loops. > > If not Django templates then what? I ideally need simple conditionals > and some way of looping. Mustache is close to what I need (it will > probably do if I cannot find better) but AFAIK cannot iterate over a > tree. I also just found > StringTemplate (from stringtemplate.org, not the standard library!), > Anyone tried either of these? > > -- > 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.
MySQL limit sub-query problem
All, I have a query. Its working fine on sqlite server but not working fine on mysql server. This is the error message on mysql server: "This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery" This is the query: inner_q = obj_unassigned.values_list('pk', flat=True)[:diff] total_objects = (obj_assigned | obj_class.objects.filter(pk__in=inner_q)) Any help appreciated on how to fix this. Thanks. RJ -- 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-post] MySQL connection pooling - preferred method??
Hey all, Not had much luck on this on django-developers, so if anyone else on django-users wants to add their two cents on this thread, that'd be great. I'm still looking into it, and it looks like the best approach is to create a new MySQL backend with support for connection pooling, but I'm still really dubious because when it gets into those depths, surely that should be in the core... *shrugs* Penny for your thoughts? :) Cal -- Forwarded message -- From: Cal Leeming [Simplicity Media Ltd] < cal.leem...@simplicitymedialtd.co.uk> Date: Wed, Jan 25, 2012 at 12:11 AM Subject: MySQL connection pooling - preferred method?? To: django-develop...@googlegroups.com, Harry Roberts < harry.robe...@simplicitymedialtd.co.uk> Hi all, After spending about 30 minutes looking through old tickets, long discussion threads and various blogs, I'm still not clear on the MySQL connection pooling topic. To quote Russ: "the capability already exists in third party tools, and they're in a position to do a much better job at it than us because it's their sole focus" [3] Could a core dev (or anyone else with experience on this) clarify which approach is recommended, on the following conditions: * Safety (should not cause any strangeness with query cache or ORM) * Performance (should avoid causing Django to open a new database connection on every request) I found various ways to accomplish this, one of which was to use SQLalchemy[1], another was to stop Django from closing the database connection after each query[2]. I'm hoping this thread will also serve as a final answer for anyone else looking for clarification. Many thanks Cal [1] http://menendez.com/blog/mysql-connection-pooling-django-and-sqlalchemy/ [2] http://stackoverflow.com/questions/1125504/django-persistent-database-connection [3] http://groups.google.com/group/django-developers/browse_thread/thread/6f1e9c6e81aff1de/bf34e546e4217277?lnk=gst=mysql+pooling#bf34e546e4217277 -- 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.
Django (or other) templates for untrusted users?
Are Django templates safe enough to use templates provided by untrusted users? Is it possible to limit functionality? I am not only concerned with what the templates can access, but also things like being able to consume excessive resources with, for example, deeply nested loops. If not Django templates then what? I ideally need simple conditionals and some way of looping. Mustache is close to what I need (it will probably do if I cannot find better) but AFAIK cannot iterate over a tree. I also just found StringTemplate (from stringtemplate.org, not the standard library!), Anyone tried either of these? -- 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: Editing .po files for RTL languages
Hello ryan, you can contact this person : taha_zerrouki(at)yahoo.com . He can help you for everything related to arabic processing. Best regards, Tarik Zakaria Benmerar Acigna Inc. CEO and Founder -- 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.
Moving a file manually
Hello, I have a model with a FileField, that I use to store some user uploaded files. After a while, I changed my mind about where to store the files, so I was just wondering if there is a way to manually move a file, and then update the location of the file as stored in the database. I'm using a plain models.FileField, with no custom Storage or anything advanced. Cheers, Tor -- 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.