Re: Dynamic template loader with TemplateResponse
Here is the solution I settled on for now. This is obviously not optimally efficient because I have to hit the filesystem twice for every page load. Does anyone know of a way to raise Http404 during template rendering? I tried it with a TemplateResponse subclass but ran into some problems with _is_rendered. I can't think of a way to handle a 404 at the template rendering stage. from django.http import Http404 from django.template import TemplateDoesNotExist from django.template.loader import get_template from django.views.generic import TemplateView class ContentView(TemplateView): def get_template_names(self): return [self.kwargs['template_name']] def render_to_response(self, context, **response_kwargs): try: get_template(self.get_template_names()[0]) except TemplateDoesNotExist: raise Http404 return super(ContentView, self).render_to_response(context, **response_kwargs) On May 23, 3:01 pm, Brian Morton wrote: > I have some legacy code that I used to dynamically load a template based on > url if it exists and render a 404 if it doesn't exist. > > def content(request, template_name='index'): > try: > return direct_to_template(request, '%s.html' % template_name) > except TemplateDoesNotExist: > raise Http404 > > I'm having difficulty conceptualizing how to do this in trunk (1.4) with > TemplateResponse. Since everything happens inside response.render() outside > of the view, I do not have that level of control at this stage. > > Should I extend BaseLoader to load the 404 template instead of raising an > exception if it is not found? Or should I extend SimpleTemplateResponse to > do something similar? Or is there a better way to do this? -- 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.
Dynamic template loader with TemplateResponse
I have some legacy code that I used to dynamically load a template based on url if it exists and render a 404 if it doesn't exist. def content(request, template_name='index'): try: return direct_to_template(request, '%s.html' % template_name) except TemplateDoesNotExist: raise Http404 I'm having difficulty conceptualizing how to do this in trunk (1.4) with TemplateResponse. Since everything happens inside response.render() outside of the view, I do not have that level of control at this stage. Should I extend BaseLoader to load the 404 template instead of raising an exception if it is not found? Or should I extend SimpleTemplateResponse to do something similar? Or is there a better way to do this? -- 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.
TemplateView and dynamic template_name in urlconf
I have a generic view that accepts its template_name attribute from the urlconf dynamic variable: (r'^(?P[^/]+)$', TemplateView.as_view()), But I get an exception: TemplateResponseMixin requires either a definition of 'template_name' or an implementation of 'get_template_names()' I've read the code and understand the difference between class attributes and the kwargs attribute. I also understand how to fix this problem by overriding get_template_names in this case. Does anyone else share my feeling that this is unclear to some users and should be better documented (the difference between initkwargs and kwargs added from the request)? -- 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: Interesting Django or Python Issue
Can we see some code? The description of what you're doing sounds just fine, so that leaves open the possibility of a technical error. On Apr 28, 7:42 am, Sam Lai wrote: > Maybe database connections aren't closing properly? Don't know where > to start looking though. > > A few weeks ago, I saw something similar (more Django and postgresql > processes than usual, not doing anything special), but it hasn't > happened since. Thinking about it, it happened when I was > reindexing/updating my Whoosh database. > > Maybe check open pipes or sockets for the Django processes? Or any > other open resources for those processes? I didn't really bother to > investigate when it happened for me as it hasn't happened since, but > seeing as it is reproducible for you, those are the things I'd take a > look at first. > > On 28 April 2010 06:04, Kenneth Loafman wrote: > > > > > Ping. Anyone? > > > Kenneth Loafman wrote: > >> Folks, > > >> I have a user command that runs, via cron, twice hourly with multiple > >> threads and queues. At the end of the run, I wait for all of the queues > >> to empty and join all of the threads. I close Xapian, print some log > >> info, and delete the pid file so another instance can run. All of this > >> is completed (log file entries and pid file deleted), yet about 3 times > >> a day, Django does not exit, leaving the task in memory, but idle. > > >> I've scratched my head over this but am getting nowhere fast. Other > >> than eating up memory, it does no harm as long as I go in and clean out > >> the old tasks, but this is getting old. > > >> Has anyone else seen this behavior? Any idea how to debug it? > > >> Environment is: > >> Ubuntu Karmic > >> Django 1.1.1-1ubuntu1 > >> Python 2.6 > >> MySQL 5.1 > > >> ...Thanks, > >> ...Ken > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group > > athttp://groups.google.com/group/django-users?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/django-users?hl=en. -- 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: Giving up PHP. ...Can't decide between Django & Rails
This is a tough question for sure. If you prefer Ruby syntax, then to me it seems clear. If it feels clunky, it won't flow properly and you won't code as well. Then again, you point out that you built a finished product quickly and you're happy with it compared to what you built with Rails. Isn't that the point ;) If you perceive that more Rails work is available, I would suggest going down that path and maintaining your "hobbyist" interest in Django. It just depends on your goals. On Apr 9, 12:06 pm, UnclaimedBaggage wrote: > Hi folks, > > I'm a long-term (8 years) PHP developer who's recently started > dabbling with Rails & Django. I REALLY like what I've seen from both > frameworks and quite frankly, am a little miffed I didn't jump on the > bandwagon earlier. > > I'm trying to decide between the two frameworks, but I'm > struggling to get out of stalemate. If anyone can offer advice, I'd be > very appreciative. Here are my current thoughts: > > WHAT I LIKE ABOUT DJANGO > * I LOVE django-admin . For the sort of work I do, which is a lot of > customised cart/cms stuff, this would save a lot of time. > * Code reusability seems superior. Opinions? > * Better perfomance? > * I've half-built a shopping cart app in Django that I'm happy with. A > quick dabble in Rails made this task seem a little more time- > consuming, and I'm not comfortable with drop-in solutions > * Server seems more stable. Using the rails dev server on a local > linux box twice threw errors I couldn't trace, then worked fine again > the next time I restarted my computer (having previously restarted the > server with no result). Is this a common problem? > > WHAT I LIKE ABOUT RAILS > * I prefer the syntax > * There seems to be a lot more work for rails...with better pay > * "Agile Rails" is a damn fantastic book. I haven't found much Django > documentation I've enjoyed as much > * Seems to be a little simpler > * Seems to have a greater depth of features > * Better AJAX integration from what I've seen > > Obviously I expect some django-tilted opinions here, but if anyone > with > experience in both can offer a balanced perspective on pros-n-cons of > each it would be a big help. > > Cheers. -- 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: inspectdb generates CharFields with 3x max_length
Thanks for the informative reply. I searched the tracker and didn't find anything about it, but I think I was not using the right terms. I had a feeling it had to do with charset and MySQLdb, and I definitely agree it is not a Django thing. I'll keep my eye on Ubuntu's changelog for MySQLdb and post here and in the ticket if I can figure anything out. On Oct 9, 2:18 pm, Karen Tracey wrote: > On Fri, Oct 9, 2009 at 12:40 PM, Brian Morton wrote: > > > This is a very strange problem, so I thought I would post here and see > > if anyone else had seen this problem. > > > I introspected a MySQL database with Python2.6 using Django SVN HEAD > > and it produced my models as expected. However, all CharFields have > > the max_length set to 3x the actual varchar field length in the db. > > For example, all char(1) or varchar(1) fields were represented with a > > max_length of 3. Has anyone ever seen this issue before? > > Searching the tracker reveals: > > http://code.djangoproject.com/ticket/5725 > > I am not sure the situation is quite as complicated as it is thought to be > in that ticket. Discussion in the ticket seems to think that the "right" > answer to return is going to be dependent on the table charset (actually, it > would need to be column, since the charset can be set per-column). > > However, near as I can tell from a couple of brief experiments, that's not > the case. For a latin1 encoded table with varchar(50) column the value > determined by inspectdb is 150. Similarly, for a utf-8 encoded table with a > varchar(32) column, the value determined by inspectdb is 96. In both cases > the value determined by inspectdb is 3x higher than the actual number of > characters that can be stored in the column, no matter the cholumn's > charset. > > Where is the 3x factor coming from? In the ticket it is mentioned that it's > related to the connection charset being utf-8. Switch the connection > charset to latin1, and the numbers get reported properly (at least for > latin1-encoded tables). > > The number in question here is the internal_size element of the description > returned by the connection cursor. The value is defined by the Python DB > API (http://www.python.org/dev/peps/pep-0249/) but I can find no good > description of what it is supposed to be, exactly. > > MySQLdb (or underlying code it is using) appears to be implementing this as > the maximum number of bytes that may be needed to hold a value returned from > this column on this connection. That is, since on the DB side the length > specification (since MySQL 4.1) describes the number of characters that may > be stored in the column, and since a character may require as many as 3 > bytes in utf-8 encoding (MySQL does not implement 4-byte utf-8 support), > some code somewhere is taking the max-length-in-characters value and > multiplying it by 3 to come up with a maximum number of bytes that may be > required to store a value from this column in the connection's charset. > > Since Django is always going to set the connection charset to utf-8, and > since inspectdb should be reporting character lengths, not byte lengths, it > might be sufficient to take the internal_size value and divide by 3 to get > character length values. That might work so long as the underlying value > returned by MySQLdb doesn't change, yet this page: > > http://benanne.net/code/?p=352 > > states the value returned is wrong and there's a fix (without giving any > details on how it is wrong, what the fix is, nor when it might appear in a > release of MySQLdb). And I don't have any more time to play with > investigation on this...but if different versions of MySQLdb are going to be > reporting different values here then fixing this in Django will be a it more > complicated than unconditionally dividing by 3though still not quite as > bad as thought to be in the ticket, I don't think. > > Karen --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
inspectdb generates CharFields with 3x max_length
This is a very strange problem, so I thought I would post here and see if anyone else had seen this problem. I introspected a MySQL database with Python2.6 using Django SVN HEAD and it produced my models as expected. However, all CharFields have the max_length set to 3x the actual varchar field length in the db. For example, all char(1) or varchar(1) fields were represented with a max_length of 3. Has anyone ever seen this issue before? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Poor performance on POSTs in production
Very strange problem going on with one of my Django sites. This only happens in my production env using Debian stable, Apache 2.2.9 with mod_python and django trunk (updated). All GET requests execute in a timely manner. However, all POSTs take way too long. I've inserted debugging into my views in production, and the delay is taking place prior to entering the view function. For instance, a simple contact form submission with 20 key/value pairs takes just over a minute to hit the first assert in the view function. I tried disabling cache and other middleware in settings. Nothing has changed recently software wise. I'm pretty stumped. Any ideas? --~--~-~--~~~---~--~~ 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 include session data in traceback
D'oh. Thanks. I was confusing load and loads. I thought they were the same thing. On Apr 30, 12:55 pm, Malcolm Tredinnick wrote: > On Thu, 2009-04-30 at 09:47 -0700, Brian Morton wrote: > > Thanks. That makes perfect sense. Since my session data is persisted > > in the db (and I don't have a cleanup script active at the moment), I > > can retrieve the pickled session data based on the session id in the > > cookie (that is in the traceback). The problem is decoding that > > session data. Can the pickle module accept a string as input and > > output the unpickled data? I know it does it with file objects via > > load, but I can't find any reference on how to do this with a string. > > The documentation for the pickle module tells all. :-) > > http://docs.python.org/library/pickle.html#pickle.loads > > 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: How to include session data in traceback
Thanks. That makes perfect sense. Since my session data is persisted in the db (and I don't have a cleanup script active at the moment), I can retrieve the pickled session data based on the session id in the cookie (that is in the traceback). The problem is decoding that session data. Can the pickle module accept a string as input and output the unpickled data? I know it does it with file objects via load, but I can't find any reference on how to do this with a string. On Apr 30, 12:43 pm, Malcolm Tredinnick wrote: > On Thu, 2009-04-30 at 04:58 -0700, Brian Morton wrote: > > I am considering filing an enhancement request but I want to check > > first to make sure this functionality doesn't already exist. > > > Is there some way to make Django include the contents of session in > > the traceback email received from a 500 error? > > It's not possible to guarantee that that information will be available > or that trying to get that information won't cause further errors. A 500 > error is because of an entirely unexpected problem and could potentially > be caused by anything, so Django should do the absolute minimum to get > out of there at that point -- talking to the database for session data > (which is still the common case for storing sessions) is not the > minimum. > > However, if you want to write your handling for those unexpected errors, > you can subclass the django.core.handlers.* class that you're using and > override the handle_unexpected_exception() method to do whatever you > would like. That's why that method is separated out. > > 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 -~--~~~~--~~--~--~---
How to include session data in traceback
I am considering filing an enhancement request but I want to check first to make sure this functionality doesn't already exist. Is there some way to make Django include the contents of session in the traceback email received from a 500 error? It is very useful in the case of debugging an error with the session (say, a missing key). I cannot find any reference to this in the docs. --~--~-~--~~~---~--~~ 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: Value proposition of Rails
Given how expensive developer time is relative to current hardware costs (especially on the x86 server platforms), it is almost always more cost effective to throw hardware at the problem than it is to spend countless hours porting apps from one language or framework to another for performance reasons. If you want examples, see the Django book's deployment section. On that same note, it is more effective to spend money on hardware (usually) than to code in a language that takes 5 times as long to develop, configure, and deploy. Configuration alone for most Java applications is enough to make your head spin. In my opinion, Django does this way better than PHP's many frameworks thanks to the "batteries included" approach. I have been developing PHP for many years, and I do so professionally. My hope is that one day more companies will go the way of Django so I can combine my play time and my work time. On Mar 19, 3:17 am, Torsten Bronger wrote: > Hallöchen! > > Malcolm Tredinnick writes: > > [...] > > > Even PHP: I mean, Flickr, Wikipedia, Yahoo -- these are some > > pretty large sites running on PHP. > > I've always wondered why anybody uses something non-Java for Web > applications. Given that Java is faster than PHP, Python etc., this > also means that you need less computing power in your server farm. > On the long run, this should *always* be worth it financially, > unless Java is a nightmare to maintain, which I don't assume. > > Granted, I use Python for our institute's internal Web application, > but I expect our traffic to be smaller than what one single > processor can handle. > > Is it because the network and the database are the limiting factors? > But even then, the part of your server farm running the interpreters > could be reduced. > > On the other hand, PHP is *highly* popular. So why is this? > > Tschö, > Torsten. > > -- > Torsten Bronger, aquisgrana, europa vetus > Jabber ID: torsten.bron...@jabber.rwth-aachen.de --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Cannot create model objects with file fields from shell
I am having trouble getting this script to work. My intent is to load images into the db in bulk from the filesystem. http://pastebin.com/m40565da9 When I execute this, I get the following error: Traceback (most recent call last): File "load_images.py", line 16, in GalleryImage.objects.create(image=file) File "/usr/lib/python2.5/site-packages/django/db/models/manager.py", line 99, in create return self.get_query_set().create(**kwargs) File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 352, in create obj.save(force_insert=True) File "/usr/lib/python2.5/site-packages/django/db/models/base.py", line 328, in save self.save_base(force_insert=force_insert, force_update=force_update) File "/usr/lib/python2.5/site-packages/django/db/models/base.py", line 388, in save_base values = [(f, f.get_db_prep_save(raw and getattr(self, f.attname) or f.pre_save(self, True))) for f in meta.local_fields if not isinstance(f, AutoField)] File "/usr/lib/python2.5/site-packages/django/db/models/fields/ files.py", line 187, in pre_save file.save(file.name, file, save=False) File "/usr/lib/python2.5/site-packages/django/db/models/fields/ files.py", line 235, in save self._dimensions_cache = get_image_dimensions(content) File "/usr/lib/python2.5/site-packages/django/core/files/images.py", line 36, in get_image_dimensions data = file.read(1024) File "/usr/lib/python2.5/site-packages/django/core/files/base.py", line 136, in read return self.file.read(num_bytes) File "/usr/lib/python2.5/site-packages/django/db/models/fields/ files.py", line 48, in _get_file self._file = self.storage.open(self.name, 'rb') File "/usr/lib/python2.5/site-packages/django/core/files/ storage.py", line 30, in open file = self._open(name, mode) File "/usr/lib/python2.5/site-packages/django/core/files/ storage.py", line 138, in _open return File(open(self.path(name), mode)) IOError: [Errno 2] No such file or directory: u'/media/PATRIOT/ djangosites/vandyke/site-media/loader-images/100_0056.jpg' It looks like it is trying to open the file before it has been initially written. Is this a bug? Or am I doing something wrong? 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: Media Root & Templates
>From the traceback, it would appear that one or more of your processors is named or formed improperly. Can you post the code from your setting.py file where you specify your processors? Not just the strings, but the entire Python structure where you define those. On Mar 1, 7:51 am, AKK wrote: > Having looked at the traceback i gather its something to do with the > imports: > > Environment: > > Request Method: GET > Request URL:http://localhost:8080/ > Django Version: 1.0.2 final > Python Version: 2.5.2 > Installed Applications: > ['django.contrib.auth', > 'django.contrib.contenttypes', > 'django.contrib.sessions', > 'django.contrib.sites', > 'django.contrib.admin', > 'akonline.blog', > 'akonline.search'] > Installed Middleware: > ('django.middleware.common.CommonMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware') > > Traceback: > File "C:\ProgLangs\Python25\lib\site-packages\django\core\handlers > \base.py" in get_response > 86. response = callback(request, *callback_args, > **callback_kwargs) > File "C:/Program Files/Apache2.2\akonline\blog\views.py" in blog > 7. return render_to_response('blogSite/index.html', locals(), > context_instance=RequestContext(request)) > File "C:\ProgLangs\Python25\lib\site-packages\django\template > \context.py" in __init__ > 104. for processor in get_standard_processors() + > processors: > File "C:\ProgLangs\Python25\lib\site-packages\django\template > \context.py" in get_standard_processors > 80. mod = __import__(module, {}, {}, [attr]) > > Exception Type: ValueError at / > Exception Value: Empty module name > > this is my views.py > > from django.shortcuts import render_to_response > from django.template import RequestContext > from akonline.blog.models import * > > def blog(request): > blog_posts = Post.objects.all().order_by("-post_date") > return render_to_response('blogSite/index.html', locals(), > context_instance=RequestContext(request)) > > i also tried importing context as well (at the same time), is there > something else i need to import or is something else wrong. > > Thanks, > > Andrew > Andrew --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Getting uploaded file content type in model save
I am working with PIL to resize and thumbnail images during a model save method. I am using SimpleUploadedFile as a wrapper to facilitate the thumbnail field's save method. SimpleUploadedFile requires that the proper content type be passed in as an argument. The trouble is, I may be working with several different types of image content, such as jpg, gif, or png. PIL handles this transparently, so that is not an issue. However, I am not sure how to get access to the content type reported by the browser for the uploaded file in the model save method. Can you access the request from a model save in the admin? Thanks in advance for your help. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Marking form field label as safe?
I am trying to do raw HTML output in a form field's label. I've tried using mark_safe on the string being passed as the label argument, but it is still escaped. Can anyone point me in the right direction 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-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: Bug in ImageFieldFile.save() ?
Thanks for the clarification. I will definitely look forward to having file-like objects work this way. I'll keep my eye out for the commit. On Aug 27, 7:23 am, "Marty Alchin" <[EMAIL PROTECTED]> wrote: > On Wed, Aug 27, 2008 at 12:37 AM, Brian Morton <[EMAIL PROTECTED]> wrote: > > The docs (and an analysis of the code) indicate that the second > > argument to save should be the content. > > >http://docs.djangoproject.com/en/dev/ref/files/file/#ref-files-file > > > I am assuming this is binary or text content to be written to the file > > in question. ImageFieldFile calls get_image_dimensions(content) in > > save, and get_image_dimensions assumes that the input is a file or > > path that can be open()ed by the file module. > > Yeah, looks like the documentation needs to be clearer there, because > your assumption is incorrect. The "content" argument to > FieldFile.save() is expected to be a File object itself, since it's > usually an UploadedFile. There's been talk about updating it to accept > any file-like object, which I'm working on, but it's not yet > available. > > If you need to pass in raw content like that, you can use > django.core.files.base.ContentFile to make a suitable File for use > with .save(). > > So, yes, there's a mismatch there, but it's the documentation that's > incomplete in this case. > > -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 -~--~~~~--~~--~--~---
Bug in ImageFieldFile.save() ?
The docs (and an analysis of the code) indicate that the second argument to save should be the content. http://docs.djangoproject.com/en/dev/ref/files/file/#ref-files-file I am assuming this is binary or text content to be written to the file in question. ImageFieldFile calls get_image_dimensions(content) in save, and get_image_dimensions assumes that the input is a file or path that can be open()ed by the file module. The end result is that you cannot call self.imagefield.save() in a model without an error. Does this seem like a bug to anyone else, or am I completely missing something? This should probably be called on the full filename AFTER the save to the ancestor class, so it gets fresh cache info should manipulation occur (http:// code.djangoproject.com/ticket/8208). Traceback: File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response 86. response = callback(request, *callback_args, **callback_kwargs) File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py" in root 173. return self.model_page(request, *url.split('/', 2)) File "/usr/lib/python2.5/site-packages/django/views/decorators/ cache.py" in _wrapped_view_func 44. response = view_func(request, *args, **kwargs) File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py" in model_page 192. return admin_obj(request, rest_of_url) File "/usr/lib/python2.5/site-packages/django/contrib/admin/ options.py" in __call__ 191. return self.change_view(request, unquote(url)) File "/usr/lib/python2.5/site-packages/django/db/transaction.py" in _commit_on_success 238. res = func(*args, **kw) File "/usr/lib/python2.5/site-packages/django/contrib/admin/ options.py" in change_view 570. self.save_model(request, new_object, form, change=True) File "/usr/lib/python2.5/site-packages/django/contrib/admin/ options.py" in save_model 367. obj.save() File "/media/MORTON USB/sites/btevents/../btevents/photos/models.py" in save 20. self.slideshow_image.save(os_path.basename(self.image.path), f.read(), save=False) File "/usr/lib/python2.5/site-packages/django/db/models/fields/ files.py" in save 262. self._dimensions_cache = get_image_dimensions(content) File "/usr/lib/python2.5/site-packages/django/core/files/images.py" in get_image_dimensions 34. file = open(file_or_path, 'rb') Exception Type: TypeError at /admin/photos/photo/9/ Exception Value: file() argument 1 must be (encoded string without NULL bytes), not str --~--~-~--~~~---~--~~ 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: Tricky newforms problem
Thanks. This works perfectly. Is there a better way to implement what I am trying to do? Also, does anyone know how I can capture these elements again in the view when processing the form? Since there are an arbitrary number of fields for songs, I don't know how many I should be looking for in cleaned_data. Ideally, I need to capture the song ids that were selected in some kind of iterable datatype, then loop through them and look them up in the model to get info for output. On Apr 11, 6:10 am, "Phil Davis" <[EMAIL PROTECTED]> wrote: > On 11/04/2008, Brian Morton <[EMAIL PROTECTED]> wrote: > [...] > > > The problem occurs in the template. I am trying to differentiate > > these fields from the other normal fields on the form for presentation > > purposes. I have tried assigning a custom property to each of the > > dynamic fields. > > > field = forms.BooleanField(label='%s (%s)' % (song.title, " & > > ".join([str(artist) for artist in song.artists.all()]))) > > field.is_song = True > > self.fields['song_%s' % song.id] = field > > > However, this custom property is not accessible in the template. How > > can I differentiate these dynamic fields from the others in the > > template (with limited access to Python code)? > > If your template looks something like: > > {% for field in form %} > {% if field._is_song %} > ... > > then the for loop 'field' is actually a boundfield instance which > wraps the real field. To get to the real field use 'field.field' in > the template. I.e. your template would look like: > >{% for field in form %} > {% if field.field.is_song %} > ... > > -- > Phil Davis --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Tricky newforms problem
I have run into an interesting problem with newforms. I am trying to create an arbitrary number of fields on a form based on model data. This works fine. class SonglistForm(forms.Form): def __init__(self, *args, **kwargs): super(SonglistForm, self).__init__(*args, **kwargs) for song in Song.objects.all()[:100]: self.fields['song_%s' % song.id] = forms.BooleanField(label='%s (%s)' % (song.title, " & ".join([str(artist) for artist in song.artists.all()]))) The problem occurs in the template. I am trying to differentiate these fields from the other normal fields on the form for presentation purposes. I have tried assigning a custom property to each of the dynamic fields. field = forms.BooleanField(label='%s (%s)' % (song.title, " & ".join([str(artist) for artist in song.artists.all()]))) field.is_song = True self.fields['song_%s' % song.id] = field However, this custom property is not accessible in the template. How can I differentiate these dynamic fields from the others in the template (with limited access to Python code)? --~--~-~--~~~---~--~~ 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: Problem with encoding and feeds
2019 is an right single quote in unicode. Perhaps that title is causing the problem? Did you paste it from some editor that would have created it as that character rather than an apostrophe? Maybe you should correct that by hand if it was pasted. On Mar 6, 7:37 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I've read over some of the gotchas with since the unicode branch > merge, and have successfully dealt with all of them up til now, but > I'm not sure what to do here... I'm throwing an error with my feed. > The same data appears on the site fine, but in my feed I get > UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in > position 24: ordinal not in range(128) > > This is the feed that's doing it. > > class NewsFeed(Feed): > title = "Classic Motorsports - What's New" > link = "/news/" > description = "Latest Classic Motorsports News" > > def items(self): > return News_item.objects.filter(pub_date__lte=now).order_by('- > pub_date')[:20] > > def item_link(self): > return "http://classicmotorsports.net/news/"; --~--~-~--~~~---~--~~ 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: Performance of a django website
http://www.djangoproject.com/documentation/db-api/#select-related On Dec 11, 1:18 pm, Joe <[EMAIL PROTECTED]> wrote: > I've found the largest memory hog to be the native way related tables > are setup. > > Check class definitions with related tables and edit as such: > > class ...(models.Mode): > relatedtable= models.ForeignKey(RelatedTable, core=True, > raw_id_admin=True) > > The raw_id_admin=True prevents django from pulling up all related > records when the object is loaded etc. While I would have expected > this to only affect the admin side, it had a huge impact on the public > side of our site. Memory consumption went from +500mb to 20-30mb. > > Joe > > On Dec 11, 12:53 pm, Richard Coleman <[EMAIL PROTECTED]> > wrote: > > > At work, we are developing a commercial website based on Django. It's a > > fairly dynamic site (think social networking). I am doing the initial > > load testing to estimate the number of servers we will need for the > > production site. The production site will be load balanced using a pair > > of BigIP boxes. > > > When I stress test the dynamic part of the site, I am only getting about > > 300 requests per second on my test setup. This is using two Dell 1950's > > (one for web, one for mysql database). These are very powerful machines > > (3.0ghz Xeons, 8 cores each, 16 gig of ram, 15k SAS drives, etc.) > > > I've done all the standard performance tuning I find when reading > > through various websites about django tuning. Is this the performance I > > should expect. > > > When I'm running the load test, the CPU on the web server gets > > completely buried (even with 8 cores). The mysql server doesn't seem > > loaded at all. Any suggestions on how to find the bottlenecks? > > > I'm running Ubuntu 7.10 (server, 64 bit version). Django from a very > > recent trunk. > > > Thanks for any advice. > > > Richard Coleman > > [EMAIL PROTECTED] --~--~-~--~~~---~--~~ 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: Performance of a django website
Sorry, just saw your earlier post about debug being turned off. I would say it is definitely time to start profiling your code. On Dec 11, 2:11 pm, Brian Morton <[EMAIL PROTECTED]> wrote: > Joseph raises a good point. I only recently discovered what a > performance killer DEBUG mode can be when it comes to queries. It > will cause your client machine (the web server in this case) to run > out of memory after a lengthy process (such as data loading). Are you > profiling in DEBUG mode? > > On Dec 11, 1:54 pm, "Joseph Heck" <[EMAIL PROTECTED]> wrote: > > > Definitely take that specific dynamic page and profile it - see what's > > happening and why its slow. That's clearly your first bottleneck to > > work on from the data you've provided. > > > There's a wiki page on that very process > > here:http://code.djangoproject.com/wiki/ProfilingDjangoandthere's > > additionally some information you can get when you enable DEBUG to see > > how long the SQL queries are taking for that dynamic page. There's a > > nice snippet to help there athttp://www.djangosnippets.org/snippets/93/ > > > -joe > > > On Dec 11, 2007 10:49 AM, Richard Coleman <[EMAIL PROTECTED]> wrote: > > > > Brian Morton wrote: > > > > Are you serving static content from the same apache instance? Also, > > > > what kind of network connectivity do you have between your web and > > > > mysql servers? It sounds like apache might need some tuning in terms > > > > of thread parameters. Have you enabled caching yet? Turn on the > > > > cache framework site-wide and set your expiration period to 1 minute > > > > or something like that. You can go back and only enable it for views > > > > that you want cached later. > > > > 1. Static content and dynamic are on the same server (that will change > > > on production). But they are on different apache virtual. Mod_python > > > is turned off for the static stuff. Hitting only a static page is very > > > fast (6500 requests per second). Hitting the dynamic side is slow (300 > > > requests per second). > > > > 2. It's gigE between the web server and mysql server, on a dedicated > > > switch. The database is working pretty hard (7000 selects per second), > > > but doesn't seem to be the bottleneck. The webserver is hammered > > > (typing any command takes a long time). > > > 3. I'm using prefork MPM on apache with maxclients set to 1000. > > > > We are starting to experiment with caching, but I want to improve the > > > raw performance of the site as well. > > > > Richard Coleman > > > [EMAIL PROTECTED] --~--~-~--~~~---~--~~ 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: Performance of a django website
Joseph raises a good point. I only recently discovered what a performance killer DEBUG mode can be when it comes to queries. It will cause your client machine (the web server in this case) to run out of memory after a lengthy process (such as data loading). Are you profiling in DEBUG mode? On Dec 11, 1:54 pm, "Joseph Heck" <[EMAIL PROTECTED]> wrote: > Definitely take that specific dynamic page and profile it - see what's > happening and why its slow. That's clearly your first bottleneck to > work on from the data you've provided. > > There's a wiki page on that very process > here:http://code.djangoproject.com/wiki/ProfilingDjangoand there's > additionally some information you can get when you enable DEBUG to see > how long the SQL queries are taking for that dynamic page. There's a > nice snippet to help there athttp://www.djangosnippets.org/snippets/93/ > > -joe > > On Dec 11, 2007 10:49 AM, Richard Coleman <[EMAIL PROTECTED]> wrote: > > > > > Brian Morton wrote: > > > Are you serving static content from the same apache instance? Also, > > > what kind of network connectivity do you have between your web and > > > mysql servers? It sounds like apache might need some tuning in terms > > > of thread parameters. Have you enabled caching yet? Turn on the > > > cache framework site-wide and set your expiration period to 1 minute > > > or something like that. You can go back and only enable it for views > > > that you want cached later. > > > 1. Static content and dynamic are on the same server (that will change > > on production). But they are on different apache virtual. Mod_python > > is turned off for the static stuff. Hitting only a static page is very > > fast (6500 requests per second). Hitting the dynamic side is slow (300 > > requests per second). > > > 2. It's gigE between the web server and mysql server, on a dedicated > > switch. The database is working pretty hard (7000 selects per second), > > but doesn't seem to be the bottleneck. The webserver is hammered > > (typing any command takes a long time). > > 3. I'm using prefork MPM on apache with maxclients set to 1000. > > > We are starting to experiment with caching, but I want to improve the > > raw performance of the site as well. > > > Richard Coleman > > [EMAIL PROTECTED] --~--~-~--~~~---~--~~ 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: Performance of a django website
Are you serving static content from the same apache instance? Also, what kind of network connectivity do you have between your web and mysql servers? It sounds like apache might need some tuning in terms of thread parameters. Have you enabled caching yet? Turn on the cache framework site-wide and set your expiration period to 1 minute or something like that. You can go back and only enable it for views that you want cached later. On Dec 11, 12:53 pm, Richard Coleman <[EMAIL PROTECTED]> wrote: > At work, we are developing a commercial website based on Django. It's a > fairly dynamic site (think social networking). I am doing the initial > load testing to estimate the number of servers we will need for the > production site. The production site will be load balanced using a pair > of BigIP boxes. > > When I stress test the dynamic part of the site, I am only getting about > 300 requests per second on my test setup. This is using two Dell 1950's > (one for web, one for mysql database). These are very powerful machines > (3.0ghz Xeons, 8 cores each, 16 gig of ram, 15k SAS drives, etc.) > > I've done all the standard performance tuning I find when reading > through various websites about django tuning. Is this the performance I > should expect. > > When I'm running the load test, the CPU on the web server gets > completely buried (even with 8 cores). The mysql server doesn't seem > loaded at all. Any suggestions on how to find the bottlenecks? > > I'm running Ubuntu 7.10 (server, 64 bit version). Django from a very > recent trunk. > > Thanks for any advice. > > Richard Coleman > [EMAIL PROTECTED] --~--~-~--~~~---~--~~ 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: Help debugging Django/MySQLdb exception
I am running with DEBUG = True. That's a good find. Thanks. I figured out the problem, but I think there is a bug here. The field from the data that I believed to be the primary key was really not a key, and duplicated itself. I had that field set as primary_key=True in the model. Thus, the "key" would repeat and the row would not be inserted. However, no exception was ever raised about a duplicate primary key on save(). I am puzzled by this. Why would it not complain about a primary key violation? On Dec 5, 12:29 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > On 12/4/07, Brian Morton <[EMAIL PROTECTED]> wrote: > > > > > I'm not sure what could be causing this problem. This is a loader > > script that is loading a CSV and using the Django ORM to do lookups > > and inserts. This is on a workstation with 1GB of memory running > > Ubuntu Gutsy (the MySQL server is local also). I'm using MySQLdb > > 1.2.2 and there do not seem to be any relevant bugs fixed since then. > > Here is the traceback. > > > Out of memory (Needed 8164 bytes) > > Traceback (most recent call last): > > File "loader.py", line 66, in > > food = Food.objects.get(nutrient_databank_number=row[0]) > > How big is what your are loading? How long does it run before you hit the > out or memory error? Are you running the script with a settings file that > has DEBUG set to True? See: > > http://code.djangoproject.com/ticket/3711 > > Karen --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Help debugging Django/MySQLdb exception
I'm not sure what could be causing this problem. This is a loader script that is loading a CSV and using the Django ORM to do lookups and inserts. This is on a workstation with 1GB of memory running Ubuntu Gutsy (the MySQL server is local also). I'm using MySQLdb 1.2.2 and there do not seem to be any relevant bugs fixed since then. Here is the traceback. Out of memory (Needed 8164 bytes) Traceback (most recent call last): File "loader.py", line 66, in food = Food.objects.get(nutrient_databank_number=row[0]) File "/usr/lib/python2.5/site-packages/django/db/models/manager.py", line 69, in get return self.get_query_set().get(*args, **kwargs) File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 261, in get obj_list = list(clone) File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 114, in __iter__ return iter(self._get_data()) File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 483, in _get_data self._result_cache = list(self.iterator()) File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 189, in iterator cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "") + ",".join(select) + sql, params) File "/usr/lib/python2.5/site-packages/django/db/backends/util.py", line 18, in execute return self.cursor.execute(sql, params) File "/var/lib/python-support/python2.5/MySQLdb/cursors.py", line 166, in execute self.errorhandler(self, exc, value) File "/var/lib/python-support/python2.5/MySQLdb/connections.py", line 35, in defaulterrorhandler raise errorclass, errorvalue _mysql_exceptions.InterfaceError: (0, '') --~--~-~--~~~---~--~~ 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: Expiring cache entries through model save()
Thanks for the advice Malcolm. I am going to give this more thought and see if I can come up with a generic high performance hash function. On Nov 30, 3:26 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Fri, 2007-11-30 at 12:08 -0800, Brian Morton wrote: > > I have an interesting idea that I am not quite sure how to pursue. > > I'm wondering if any of you have figured this out already. > > > What I would like to do is set the cache expiration for a particular > > object in the cache to be very high, and then delete the item from the > > cache when an instance of its model is saved. This would be > > particularly useful for a site where the data only changes through the > > admin interface, and not very frequently. This way, the object can > > stay cached as long as it has not changed. > > > I was thinking of trying something with the post_save signal and the > > cache middleware. Has anyone tried this already? Or is this a bad > > idea? > > The usually difficult part of this type of proposal is querysets. You > need to find every cached queryset that contains the model in question > and delete it as well. This essentially requires scanning every queryset > (or coming up with a really good hash function to enable cutting down > the search set). There was a Summer of Code project that tried to do > this, but it didn't seem to go anywhere. > > 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Expiring cache entries through model save()
I have an interesting idea that I am not quite sure how to pursue. I'm wondering if any of you have figured this out already. What I would like to do is set the cache expiration for a particular object in the cache to be very high, and then delete the item from the cache when an instance of its model is saved. This would be particularly useful for a site where the data only changes through the admin interface, and not very frequently. This way, the object can stay cached as long as it has not changed. I was thinking of trying something with the post_save signal and the cache middleware. Has anyone tried this already? Or is this a bad idea? --~--~-~--~~~---~--~~ 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: Backend does not find views
Deleting your checkout and re-checking out the SVN tree couldn't hurt. Can you tell us more about your environment? What OS? What version of Python? What web server are you using? On Oct 29, 3:53 am, oversize <[EMAIL PROTECTED]> wrote: > Hello, > my (very strange) problem is: When i want to enter the backend, i get > an import error that "ViewDoesNotExist at /admin/ > Could not import views. Error was: No module named views". > The Highlightet code is in Line 28 of 'django/contrib/admin/templates/ > admin/base.html' and the statement that does not find admin.views is > this: {% > trans 'Documentation' %} > > The even stranger thing is, this happends occasionally. Means if i > refresh,the view gets displayed.But then i want to edit some data the > view is not found anymore again, and after (some) refresh's its there > again. Looks like i somehow borked my django installation, but how > could this happend? i never touched any django files. I use the svn > version and check out regulary every few days but this did not help > either. Maybe deleting the tree and checking out a fresh one could > help? Any ideas? > > -- > Thank you > Manuel --~--~-~--~~~---~--~~ 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: Problems with deploying django
I would remove your source built code and reinstall python2.5 and the development package for it. Make sure any other versions of python are uninstalled unless other packages depend on them. On Sep 10, 3:11 pm, shabda <[EMAIL PROTECTED]> wrote: > I am trying to deploy django on a fedora 7 system. > After following these steps I am stuck! > (Long tale of woes ahead, If you can just tell me where can I get apxs > for apache, my problem is solved.) > > 1. Downloaded django, tried running setup.py, got an error saying > something like > unable to open /usr/lib/ > python2.5/config/Makefile (No such file or > directory) > 2. Googled a bit, found that there is some error with my packaging. > 3. So installed python from the source. > 4. Installed mod_python, using yum install mod_python > 5. Made changes to httpd.conf > 6. Tried running the page getting an error like > "ImportError: No module named django.core.handlers.modpython" > 7. Started python,>>> import django > > So python is in my pythonpath > 8. >>>import mod_python > Exception > 9. Hmm looks like mod_python is getting installed to a different > python. > 10. yum remove mod_python , yum install mod_python > 11. Still no luck. > 12. Removed mod_python, tried building mod_python from source. Getting > error like, > "configure: WARNING: apxs was not found, DSO compilation will not > be available." > 13. Stuck. Cant find how to get apxs. --~--~-~--~~~---~--~~ 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: Django Flatpages With Memcache as storage location
What happens if you use a simple or dummy cache? On Sep 9, 2:51 pm, Sasha Weberov <[EMAIL PROTECTED]> wrote: > On Sep 9, 6:15 am, Thomas Badran <[EMAIL PROTECTED]> wrote: > > > > > My best guess would be that you are missing the / at the start and end > > of the url > > > Tom > > > On Sat, 2007-09-08 at 21:00 -0700, Sasha Weberov wrote: > > > All of my flatpage pages throw a 404. If I turn debug on which > > > disabled cacheing they re-appear. I've tried restarting memcached and > > > my SCGI server as well as Apache and it did nothing. I've also svn'd > > > the latest Django trunk; the problem still persists. Anyone got any > > > idea what can possibly be causing this? > > > > Here is my settings.py middlewear config. The Middlewear seems to be > > > in the correct order. > > > > MIDDLEWARE_CLASSES = ( > > > 'django.middleware.common.CommonMiddleware', > > > 'django.contrib.sessions.middleware.SessionMiddleware', > > > 'django.contrib.auth.middleware.AuthenticationMiddleware', > > > 'django.middleware.doc.XViewMiddleware', > > > 'django.middleware.cache.CacheMiddleware', > > > 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware', > > > ) > > > > Any help or suggestions would be greatly appreciated.- Hide quoted text - > > > - Show quoted text - > > I've looked at that, all of my urls are /faq/ /tos/ /privacy/ etc. The > flat pages load with Debug on, but with it off they don't. I believe > this is because Debug On turns cacheing off. --~--~-~--~~~---~--~~ 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: Databases, one or many
Possibly. I have never heard of this and I do not do it. If I were just making random applications for distribution to others I might consider it, but most of the time I am making an application for a specific purpose or organization/company. In that case, I create a project for the org/company/website and put the separate apps (based on function) under the project. On Sep 6, 4:49 pm, "Adam Jenkins" <[EMAIL PROTECTED]> wrote: > On 9/6/07, Brian Morton <[EMAIL PROTECTED]> wrote: > > > > > Well, by its nature, each Django project has its own DB. Multi-db > > support is coming soon, but not in trunk yet. > > > If these are all applications that belong to the same project, Django > > is not designed to handle them on a per-DB basis. The convention > > Django uses is a DB for the project and _ for the > > tables. This should not prevent any conflicts since a Python error > > would occur if you duplicated a model within your app's model. I am > > not aware of any MySQL limit on tables per DB, nor should it make a > > difference from a performance perspective. Just keep in mind that > > these apps will all share a single admin interface, and while there > > are some access controls, they may not be granular enough for what you > > need. That may drive your requirement to move some of these apps to a > > separate project. > > This actually brings up an issue. I've heard that many Django developers > don't > use projects at all, that they just use apps. Is this correct? Should I > default to one > project and break it up into smaller ones if the need arises? > > On Sep 6, 4:27 pm, "Adam Jenkins" <[EMAIL PROTECTED]> wrote: > > > > I'm moving old php apps to Django. All the old php apps each have their > > own > > > DB. So I'm deciding now if I should just put everything inside a big DB. > > I > > > think when I'm all done, I could easily push 200 tables. Almost all of > > these > > > are intranet apps, so the load is pretty small. Is one large DB an > > issue, or > > > are there any other problems I should look out for? > > > > -- > > > --- > > > Adam Jenkins > > > [EMAIL PROTECTED] > > > 312-399-5161 > > > --- > > -- > --- > Adam Jenkins > [EMAIL PROTECTED] > 312-399-5161 > --- --~--~-~--~~~---~--~~ 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: Databases, one or many
Well, by its nature, each Django project has its own DB. Multi-db support is coming soon, but not in trunk yet. If these are all applications that belong to the same project, Django is not designed to handle them on a per-DB basis. The convention Django uses is a DB for the project and _ for the tables. This should not prevent any conflicts since a Python error would occur if you duplicated a model within your app's model. I am not aware of any MySQL limit on tables per DB, nor should it make a difference from a performance perspective. Just keep in mind that these apps will all share a single admin interface, and while there are some access controls, they may not be granular enough for what you need. That may drive your requirement to move some of these apps to a separate project. On Sep 6, 4:27 pm, "Adam Jenkins" <[EMAIL PROTECTED]> wrote: > I'm moving old php apps to Django. All the old php apps each have their own > DB. So I'm deciding now if I should just put everything inside a big DB. I > think when I'm all done, I could easily push 200 tables. Almost all of these > are intranet apps, so the load is pretty small. Is one large DB an issue, or > are there any other problems I should look out for? > > -- > --- > Adam Jenkins > [EMAIL PROTECTED] > 312-399-5161 > --- --~--~-~--~~~---~--~~ 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: sporadic VariableDoesNotExist's...
Also, do you have django.core.context_processors.request in your context_processors? It looks like you're trying to overwrite a dict element that already exists. On Sep 6, 12:14 pm, Bram - Smartelectronix <[EMAIL PROTECTED]> wrote: > Hello Everyone, > > I have a request context which sets {'request':request}... > > On windows (dev-server) everything is fine and dandy, but on our live > site (splicemusic.com, Apache2 + mod_python) I see *sporadic* > appearances of: > > "VariableDoesNotExist: Failed lookup for key [request] in [{}]" > > Does anyone have any idea what this could mean? The strange part is that > the same page will sometimes trigger the error and sometimes... not! > > - bram --~--~-~--~~~---~--~~ 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: sporadic VariableDoesNotExist's...
Can we see your context processor code? On Sep 6, 12:14 pm, Bram - Smartelectronix <[EMAIL PROTECTED]> wrote: > Hello Everyone, > > I have a request context which sets {'request':request}... > > On windows (dev-server) everything is fine and dandy, but on our live > site (splicemusic.com, Apache2 + mod_python) I see *sporadic* > appearances of: > > "VariableDoesNotExist: Failed lookup for key [request] in [{}]" > > Does anyone have any idea what this could mean? The strange part is that > the same page will sometimes trigger the error and sometimes... not! > > - bram --~--~-~--~~~---~--~~ 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: update 2nd model via first when saved
class Hardware(models.Model): blah = models.CharField() ... #called every time the model instance is saved def save(): #if you want many hardware history records for a piece of hardware history = HardwareHistory.create(hardware=self, ...) #if you only want 1 hardware history record for update each time (not good relational structure) history = HardwareHistory.get_or_create(hardware=self, ...) class HardwareHistory(models.Model): hardware = models.ForeignKey(Hardware) hotani wrote: > I am attempting to avoid writing a custom admin page. There are at > most two people that will be updating the database, and this seems > like a great job for the django admin area. > > However, for this to work I need a way to update a 2nd model (a > history table) when another model is updated. Is this possible? I was > hoping there would be a way to do it via model method, but have not > found anything yet. > > Example: > > Model 1 (hardware items): > id > date_modified > location > last_action > ...many other fields... > > Model 2 (history table): > hardware_id > location > action > date > > The idea is to be able to look up a hardware item, then view its > history: what locations it has been to, dates and actions. I can in > theory have them update the history table every time an items status > changes, but I don't think that is a very friendly solution. It would > be nice to update the history table every time a hardware item was > changed. Better yet, every time a specific field in the hardware table > changed (such as location or last action). --~--~-~--~~~---~--~~ 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: A "revision-controlled field" type?
It sounds like what you need to build is a custom ForeignKey type of field that creates another table for that field. Then, you can store an arbitrary number of revisions of that field, along with versioning information, and a wrapper around diff that can perform the functions you mention. On Aug 16, 5:54 pm, Tim Chase <[EMAIL PROTECTED]> wrote: > > I'm not sure I really understand. It sort of sounds like you are > > talking about a CharField with a choices argument. Is what you're > > looking for more complex? > > No...a "choices" argument assumes you know what you want in the > field beforehand...yes, I'm looking for a headache :) > > > Can you describe it in more detail? > > It would be like a TextField that behaves like the contents of an > RCS ",v" file. As the item is saved, past revisions are > maintained and only deltas are applied. Past revisions can be > extracted. Much like your average wiki edit-field. > > Theoretically, one could bind to an existing library like the > "bzr" revision-control libraries (graciously already written in > Python), mercurial/hg (also written mostly in python), SVN or CVS > (providing python interfaces, but to non-Django-DB backend > storage from my understanding) and hook into their ability to > manage the content as revisions. Even a "rcs.py" or something > like that would be sufficient as long as it could work with a > string-object rather than having to marshall files. > > Such fields would have ways of extracting various revisions and > differences between revisions. > > Sample usage of this imaginary field type (adjust for > apropriateness): > > class Foo(Model): >title = CharField(maxlength=42) >body = RevisionControlField() > > >>> f = Foo.objects.create(title='This is a test', body=""" > ... line 1 > ... Hello world > ... line 3 > ... """) > ... > >>> f.save() > >>> f.body = """ > ... line 1 > ... Goodbye world > ... line 3 > ... """) > >>> f.save() > >>> f.body = """ > ... line 1 > ... Aloha world > ... line 3 > ... """) > >>> f.body.diff() > [output showing "Goodbye" -> "Aloha" in your favorite diff > format, or perhaps a "diff" object] > >>> f.body.diff(1) #diff with > [output showing "Hello" -> "Aloha" in your favorite diff format, > or perhaps a "diff" object] > >>> f.body.revert() # now back at version 2 with "Goodbye" > >>> f.body[1] > """ line 1 >Hello world >line 3 >""" > >>> f.body.revisions > 2 > > Hope this clarifies what I'm hunting for. Thanks though! > > -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: A "revision-controlled field" type?
I'm not sure I really understand. It sort of sounds like you are talking about a CharField with a choices argument. Is what you're looking for more complex? Can you describe it in more detail? On Aug 16, 4:06 pm, Tim Chase <[EMAIL PROTECTED]> wrote: > Has there been any work on a "RevisionControlledField" type? > Likely, a standard text-field with some controls for selecting > versions or branches thereof, and saving becomes a bit complicated. > > I'm looking for ideas/suggestions/caveats for such a field (and > if such a beast already exists, perhaps simply reusing it instead > of rolling my own). > > Thanks, > > -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: Newforms file upload
I hit reply to author instead of reply. I think that is definitely the problem. I assumed that the file data would be in request.POST. I will go back and re-read the docs for newforms since it sounds like there are some API changes. Thanks to everyone who worked on this ticket, including Malcolm. Resolving it takes newforms forward a giant step. On Aug 15, 8:51 am, "Jonathan Buchanan" <[EMAIL PROTECTED]> wrote: > On 8/15/07, Brian Morton <[EMAIL PROTECTED]> wrote: > > > > > As I understand it, ticket 3297 is closed as resolved. However, I am > > still experiencing problems uploading files in newforms as of the > > latest svn checkout. Am I incorrect in my assumption that this has > > been fixed? Or am I experiencing issues of my own? Thanks. > > What kind of problems are you experiencing? > > I was scratching my head for a few minutes the first time I tried to > use newforms FileField, only to realise that I'd forgotten to pass > request.FILES with the new "files" argument when creating my form > instances. > > Jonathan. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Newforms file upload
As I understand it, ticket 3297 is closed as resolved. However, I am still experiencing problems uploading files in newforms as of the latest svn checkout. Am I incorrect in my assumption that this has been fixed? Or am I experiencing issues of my own? 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 -~--~~~~--~~--~--~---
Re: Rails-like Flash in Django
Django also makes use of "messages" in the django.contrib.auth module for this purpose. Of course, that only applies if you are using users and authentication for your site. I think you can use them with anonymous users though, so I think they will still work for you. http://www.djangoproject.com/documentation/authentication/#messages On Aug 10, 3:20 pm, sagi s <[EMAIL PROTECTED]> wrote: > In Rails, flash is a way to display a message in the next page. It is > extremely useful to provide lightweight feedback to user operations. > For examples when the user, say, submits a new article and after > clicking on the "Submit" button, then is redirected to the front page, > you want to let him know that his submission was successful on the > front page. > > What you would like to do is something like this: > > ...views.py > def new_article(request): > ... > article.save() > flash("Your article was saved") > ... > HttpRedirect("frontpage") > > I have implemented as a context processor: > > Step 1: > create a file called session_context_processor.py: > def flash(request): > # Add the flash message from the session and clear it > flash = "" > if 'flash' in request.session: > flash = request.session['flash'] > del request.session['flash'] > return {'flash': flash} > > Step 2: > Add the context processor to settings.py: > TEMPLATE_CONTEXT_PROCESSORS = ( > 'django.core.context_processors.auth', > ... > 'session_context_processor.flash', > ) > > Step 3: > Add the context to *every* view that renders a template: > e.g. change: > return render_to_response('mytemplate.html', context) > to: > return render_to_response('mytemplate.html', context, > context_instance=RequestContext(request)) > Again: do this in every view which should be displaying a flash (I > have it in all views) > > Step 4: > Add the flash message to your base template: > ... > ... {{ flash }} > ... > > Step 5: > Set the flash whenever desired. Following the example above: > ...views.py > def new_article(request): > ... > article.save() > request.session['flash'] = "Your article was saved" > ... > HttpRedirect("frontpage") > > That's it. > > I've seen other pointers on how to do it but this one makes sense to > me. > > One thing I want to add is a flash type to help the template format > the flash differently depending on whether it represents an error, > successful operation etc. > > Suggestions for improvement are welcome. --~--~-~--~~~---~--~~ 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: Unique=true
If you are using NewForms, you should implement this in the clean() method for a field. See the newforms docs and unit tests for more details. On Jul 16, 4:49 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > OK, fixed the above problem -- figured out that it was related to my > setting unique=True on a field. But that raises the larger question... > > I have a bit of data that may or may not exist... a identifier on the > user that not all users will have, but if they DO have it, it needs to > be unique to that user. Apparently, unique=True isn't what I want, > because the second user without it throws the above duplicate entry > error, so how do I handle that? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Related field has invalid lookup: iexact
I am getting the following error in my application's admin area trying to add a record for a particular object. It seems to stem from the fact that I am relating this record to a "member" object, and a member is OneToOne with User. If I relate the object directly to User as a foreignkey, I have no problems. Error and trace. http://www.parsed.org/paste/13/ Pertinent models. http://www.parsed.org/paste/14/ I'm using svn trunk version of Django and Python 2.5 on Windows. --~--~-~--~~~---~--~~ 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: Anyone running Django and MySQL Cluster
I have not done this before with Django, but I have set up a MySQL cluster before. It is the same as a standard MySQL server. Just connect to the management node as your SQL server. On Jul 6, 3:01 pm, johnny <[EMAIL PROTECTED]> wrote: > Is it even possible to run Django and MySQL Cluster or I have to write > some patch to django for it to work (I am not a python or Django > guru.)? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Multiple models on one form
I am trying to write a custom form that will handle updates for several models. What is the best way to do this? Do I have to write a custom manipulator to handle the data? Or can I create a hybrid view of several different default manipulators? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Validation Summary
I can't figure out how to make a validation summary on a form. I have examined the code in forms\__init__.py, and it reveals nothing about where the complete list of field/error pairs are stored. I would like to do a for loop on that dictionary and output a validation summary, then mark each field with a simple * (which I already know how to do). --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---