Re: installation issues
Can you tell us what version of Django you tried to install and what exact steps you took? I am using the Django development version on a mac and 'import django' works just fine. I would recommend you install svn through the link below: http://metissian.com/downloads/macosx/subversion/subversion-client-1.3.1.dmg Then follow the instructions from the link below to the letter and everything should work just fine. http://www.djangoproject.com/documentation/install/#installing-the-developme nt-version Best, Vincent On 7/12/07 10:42 PM, "surfwizz" <[EMAIL PROTECTED]> wrote: > > I installed python from www.python.org, so the command prompt opens it > into 2.5.1. That's what I tried to install django into. > > On Jul 12, 8:04 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]> > wrote: >> On 7/13/07,surfwizz<[EMAIL PROTECTED]> wrote: >> >> >> >>> I tried that originally. I'm sorry that I thought that you meant that >>> I should try it as >>>import Django. Anyway, here's what >>>import >>> django looks like: >>> Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04) >> >> Ok - your prompt is reporting Python 2.5, but you're talking about >> installing on OSX 10.4. OSX 10 ships with Python 2.3. >> >> What part of the story aren't you telling us? >> >> Yours, >> Russ Magee %-) > > > > -- Vincent R. Nijs Assistant Professor of Marketing Kellogg School of Management, Northwestern University 2001 Sheridan Road, Evanston, IL 60208-2001 Phone: +1-847-491-4574 Fax: +1-847-491-2498 E-mail: [EMAIL PROTECTED] Skype: vincentnijs --~--~-~--~~~---~--~~ 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: installation issues
You already told us that. Don't use Django but django. The command is case-sensitive. import django Vincent On 7/12/07 4:34 PM, "surfwizz" <[EMAIL PROTECTED]> wrote: > > Here's what that looks like: >>>> import Django > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named Django >>>> > > > On Jul 12, 2:19 pm, Vincent Nijs <[EMAIL PROTECTED]> > wrote: >> How about 'import django' rather than 'import Django'? >> >> Vincent >> >> On 7/12/07 4:15 PM, "surfwizz" <[EMAIL PROTECTED]> wrote: >> >> >> >> >> >>> When I run python in terminal, then use >>>import Django, here's what >>> it looks like. >>> Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04) >>> [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin >>> Type "help", "copyright", "credits" or "license" for more information. >>>>>> import django >>> Traceback (most recent call last): >>> File "", line 1, in >>> ImportError: No module named django >> >>> On Jul 10, 9:09 pm, Carl Karsten <[EMAIL PROTECTED]> wrote: >>>> surfwizzwrote: >>>>> I am having trouble installing Django on Mac OSX 10.4.10. Any help >>>>> would be welcome. Thanks! >> >>>> Im gona take a shot: >> >>>> Can you run python and get a >>> prompt? >> >>>> If yes, >>>>what version is it? >>>>and what happens when you >>> import django >> >>>> Carl K >> >> -- > > > > -- Vincent R. Nijs Assistant Professor of Marketing Kellogg School of Management, Northwestern University 2001 Sheridan Road, Evanston, IL 60208-2001 Phone: +1-847-491-4574 Fax: +1-847-491-2498 E-mail: [EMAIL PROTECTED] Skype: vincentnijs --~--~-~--~~~---~--~~ 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: installation issues
How about 'import django' rather than 'import Django'? Vincent On 7/12/07 4:15 PM, "surfwizz" <[EMAIL PROTECTED]> wrote: > > When I run python in terminal, then use >>>import Django, here's what > it looks like. > Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04) > [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin > Type "help", "copyright", "credits" or "license" for more information. import django > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named django > > > On Jul 10, 9:09 pm, Carl Karsten <[EMAIL PROTECTED]> wrote: >> surfwizzwrote: >>> I am having trouble installing Django on Mac OSX 10.4.10. Any help >>> would be welcome. Thanks! >> >> Im gona take a shot: >> >> Can you run python and get a >>> prompt? >> >> If yes, >>what version is it? >>and what happens when you >>> import django >> >> Carl K > > > > -- --~--~-~--~~~---~--~~ 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: Generating graphs from db data and displaying results using Django?
http://www.scipy.org/Cookbook/Matplotlib/Django On 7/11/07 12:06 PM, "Forest Bond" <[EMAIL PROTECTED]> wrote: > On Wed, Jul 11, 2007 at 04:56:03PM -, [EMAIL PROTECTED] wrote: >> >> I would actually suggest using Django to create a web service to get >> the data, and a JavaScript charting library to do the drawing client- >> side. > > Why not create the graphs on the server? > > -Forest --~--~-~--~~~---~--~~ 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: Error log interpretation
Graham, Looks like you are right. If I hit the reload button repeatedly this message pops up in the error logs. Doesn't seem like a serious error then. Thanks for helping me sort that out! Vincent On 7/5/07 9:47 PM, "Graham Dumpleton" <[EMAIL PROTECTED]> wrote: > > On Jul 6, 9:38 am, Vincent Nijs <[EMAIL PROTECTED]> > wrote: >> Could anyone help me identify if the error message below (from apache log) >> might be a network/apache error or something in my Django/python code. My >> site is deployed using apache and mod_python. >> >> [error] [client ] PythonHandler django.core.handlers.modpython: Traceback >> (most recent call last):, referer:https://mysite.org >> [error] [client ] PythonHandler django.core.handlers.modpython: File >> "/usr/lib/python2.5/site-packages/mod_python/apache.py", line 299, in >> HandlerDispatch\nresult = object(req), referer:https://mysite.org >> [error] [client ] PythonHandler django.core.handlers.modpython: File >> "/usr/lib/python2.5/site-packages/django/core/handlers/modpython.py", line >> 177, in handler\nreturn ModPythonHandler()(req), >> referer:https://mysite.org >> [error] [client ] PythonHandler django.core.handlers.modpython: File >> "/usr/lib/python2.5/site-packages/django/core/handlers/modpython.py", line >> 169, in __call__\nreq.write(chunk), referer:https://mysite.org >> [error] [client ] PythonHandler django.core.handlers.modpython: IOError: >> Write failed, client closed connection., referer:https://mysite.org > > The IOError simply indicates that the browser connection was closed > before a response could be completely sent. Did you press the stop or > reload buttons on the browser in the middle of a page load? > > Graham > > > > -- Vincent R. Nijs Assistant Professor of Marketing Kellogg School of Management, Northwestern University 2001 Sheridan Road, Evanston, IL 60208-2001 Phone: +1-847-491-4574 Fax: +1-847-491-2498 E-mail: [EMAIL PROTECTED] Skype: vincentnijs --~--~-~--~~~---~--~~ 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: ubuntu 6.06 deployment issues
Maybe an example would be useful as well: == Apache conf file === ServerName site.com ServerAdmin [EMAIL PROTECTED] DocumentRoot /home/user/django/site SetHandler python-program PythonPath "['/home/user/django'] + sys.path" PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE recruiting_new.settings #PythonDebug On SetHandler None SetHandler None Site_media is a sub-directory in my site directory. Admin_media is a short-cut to the django_src/django/contrib/admin/media directory. The short-cut is also in the site directory. == settings.py file === MEDIA_ROOT = '/home/user/django/site/site_media/' ADMIN_MEDIA_PREFIX = '/admin_media/' Templates: TEMPLATE_DIRS = ( '/home/user/django/site/templates', ) This works for me. Vincent On 7/6/07 12:09 AM, "Jeremy Dunck" <[EMAIL PROTECTED]> wrote: > > On 7/5/07, John-Scott <[EMAIL PROTECTED]> wrote: >> In my settings.py, I now have: >> MEDIA_ROOT = '/var/www/mysite.com/media/' >> MEDIA_URL = 'http://mysite.com/media/' >> ADMIN_MEDIA_PREFIX = '/media/' > > Err, I don't have my code or settings file handy. This is the kind > of thing you forget, since it just works once you have it configured. > > But if you plan to serve media other than admin, you'll want to nest > the admin media dir inside your regular media url. > > So maybe you want MEDIA_URL = http://mysite.com/media/ and > ADMIN_MEDIA_PREFIX = 'http://mysite.com/media/admin/' > >> Anyway, want to say thanks again to everyone for chiming in, this is >> one of the friendliest and most helpful user groups I've had the >> pleasure of participating in. > > That makes me feel kinda fuzzy. :) > -Jeremy > > > -- Vincent R. Nijs Assistant Professor of Marketing Kellogg School of Management, Northwestern University 2001 Sheridan Road, Evanston, IL 60208-2001 Phone: +1-847-491-4574 Fax: +1-847-491-2498 E-mail: [EMAIL PROTECTED] Skype: vincentnijs --~--~-~--~~~---~--~~ 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: ubuntu 6.06 deployment issues
Try adding the following in the location block: PythonPath "['/home/john-scott/workspace'] + sys.path" Vincent On 7/5/07 9:03 PM, "John-Scott" <[EMAIL PROTECTED]> wrote: > > Hello all, > > I'm having some issues getting a basic django project in production > mode. > > I'm using Ubuntu 6.06 LTS with the default versions of apache, python, > mod_python, etc. > - I've checked out the development version of Django in my home > directory, i.e. /home/john-scott/workspace/django_src and I've > symlinked it to /usr/lib/python2.4/site-packages/django as per the > official installation instructions. > - I've created a Django project in /home/john-scott/workspace/mysite > following the tutorials exactly. > > The official documentation suggests keeping the django app code > outside of /var/www for security purposes and to instead keep the code > in a user directory (the specific example is '/home/mycode'). > Everything works great with the development server. However, I've > encountered nothing but problems trying to go 'live'. I'm using the > following virtual host configuration, which again is modeled after the > official docs: > > > ServerNamemysite.com #obviously not the real url ;) > > SetHandler python-program > PythonHandler django.core.handlers.modpython > SetEnv DJANGO_SETTINGS_MODULE mysite.settings > PythonDebug On > > > > With this setup I get the following error: > ImportError: No module named django > > In another thread (http://groups.google.com/group/django-users/ > browse_thread/thread/e44569d185e36284/) someone said there were > permission problems but their solution was to place the django_src in / > opt and change the symlink accordingly. If I follow this, then the > first problem goes away but then I get the following error: > EnvironmentError: Could not import settings 'mysite.settings' (Is it > on sys.path? Does it have syntax errors?): No module named > mysite.settings > > In the same thread the user also put the projects in /opt as well. The > real problem seems to be the Apache configuration, so I'm not > convinced the answer is to throw everything in /opt, especially since > none of the official docs suggest to do such a thing (IIRC the user in > that thread didn't have control over apache, so they had to be > creative). > > I've followed all the official docs quite literally. Is the suggestion > in the docs to keep your projects in /home/username incorrect? Or is > there something about the Apache configuration in Ubuntu 6.06 that > makes deployment a wee bit more complicated than the docs suggest? If > so, should the official deployment guides have a note about these > gotchas? Once I get this ironed out in a sane way I'd be happy to add > a write-up to the SeverArrangements wiki page. > > Thanks, > John-Scott > > > > -- Vincent R. Nijs Assistant Professor of Marketing Kellogg School of Management, Northwestern University 2001 Sheridan Road, Evanston, IL 60208-2001 Phone: +1-847-491-4574 Fax: +1-847-491-2498 E-mail: [EMAIL PROTECTED] Skype: vincentnijs --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Error log interpretation
Could anyone help me identify if the error message below (from apache log) might be a network/apache error or something in my Django/python code. My site is deployed using apache and mod_python. [error] [client ] PythonHandler django.core.handlers.modpython: Traceback (most recent call last):, referer: https://mysite.org [error] [client ] PythonHandler django.core.handlers.modpython: File "/usr/lib/python2.5/site-packages/mod_python/apache.py", line 299, in HandlerDispatch\nresult = object(req), referer: https://mysite.org [error] [client ] PythonHandler django.core.handlers.modpython: File "/usr/lib/python2.5/site-packages/django/core/handlers/modpython.py", line 177, in handler\nreturn ModPythonHandler()(req), referer: https://mysite.org [error] [client ] PythonHandler django.core.handlers.modpython: File "/usr/lib/python2.5/site-packages/django/core/handlers/modpython.py", line 169, in __call__\nreq.write(chunk), referer: https://mysite.org [error] [client ] PythonHandler django.core.handlers.modpython: IOError: Write failed, client closed connection., referer: https://mysite.org Interestingly Django did not send me any emails about this error even though debug = False. Thanks much, Vincent --~--~-~--~~~---~--~~ 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: newbie: trying to understand django templates
They worked for me. So you maybe missing something :) Is urls.py still trying to import the hours_ahead function? If that doesn't help try posting your code. Vincent On 7/2/07 6:36 PM, "walterbyrd" <[EMAIL PROTECTED]> wrote: > > I continue to be frustrated with examples given in this book, which > simply do not work. I am trying to follow the code examples in the > book. > > In chapter 4, the book gives this code example: > > from django.shortcuts import render_to_response > import datetime > > def current_datetime(request): > now = datetime.datetime.now() > return render_to_response('current_datetime.html',{'current_date': > now}) > > This is supposed to replcae the old current_datetime routine. But it > doesn't work. Instead I get this error: > > cannot import name hours_ahead > > Although there are no instructions to do so, I commented out the > reference to hours_ahead in the urls.py. and removed the hours_ahead > function from views.py. But it still doesn't work. > > > > > -- --~--~-~--~~~---~--~~ 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: index.html
Why not just put (r'^$', home) in your urls.py, pointing to home in views.py which renders an html page as you would with your other pages? Vincent On 7/2/07 2:16 PM, "Carl Karsten" <[EMAIL PROTECTED]> wrote: > > Dennis Kaarsemaker wrote: >> On ma, 2007-07-02 at 12:49 -0500, Carl Karsten wrote: >>> how do I set a default anything for when a user hits http://foo.com they get >>> index.html or any other file? I can see having a static file that does a >>> redirect - wondering if there isn't a better way. >> >> If your root is served by django, > >> you use apach: try Mod_Rewrite. >> > > yeah, for the dev server. > >> put it in your urlconf. > > Put what? > I currently have > > (r'^(?P.*)$', 'django.views.static.serve', > {'document_root':'/home/carl/django/ridgemoor', 'show_indexes':True} ), > > which gives me a index.html link I can click on - trying to skip that step. > > Carl K > > > -- --~--~-~--~~~---~--~~ 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: newbie: trying to understand django templates
By using: python manage.py shell all the 'settings' are taken care of for you so you don't have to do any exports or anything like that. The import statement for Context and Template should work fine when you use the above command. Vincent On 7/2/07 2:14 PM, "walterbyrd" <[EMAIL PROTECTED]> wrote: > > I am going through the django book. I am on Chapter 4: The Django > template system. > > In the example given, the first line reads: > from django.template import Template, Context > > But, that will produce a screen full of errors. > > In the comments, it is suggested to change to the directory in which > manage.py resides, and run: > > python manage.py shell > > That works, but I don't know why. That command runs iPython, but not > just iPython. If I try to just run iPython without that "python > manage.py shell" command, I get the same errors when I try the "from > django.template import Template, Context" > > This is also in the comments: > > --- > Be sure to mention to users to set the environment variable > DJANGO_SETTINGS_MODULE: > > export DJANGO_SETTINGS_MODULE=settings > --- > > I'm sorry, but I'm just getting started. These people are going *way* > over my head. Could somebody explain what is going on? > > > > -- --~--~-~--~~~---~--~~ 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: Newbie Question: site working in dev, not in production...probable issue with httpd.conf
If you change your conf settings to the following do you still have the same problem? SetHandler python-program PythonPath "[ '/usr/local/django_projects/' ] + sys.path" PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE beijing_eats.settings PythonDebug On Also, I think you may want to add something like the following to your configuration file to handle media. SetHandler None Best, Vincent On 7/2/07 11:21 AM, "Wiley" <[EMAIL PROTECTED]> wrote: > > Here's the ultra-newbie question of the day. > > I have a lil' site running well under runserver, when I hook it up to > apache2 and mod_python, something goes wrong. For the EXACT same > python/django code, the admin site and all URLS come up fine in the > built-in server. When I switch to the apache setup I get nothing but > 404s, and I know its reading my urls file because it's saying it tried > those urls. Am I missing something obvious? > > Here's my httpd.conf settings: > > > SetHandler python-program > PythonPath "[ '/usr/local/django_projects/beijing_eats/' ] + > sys.path" > PythonHandler django.core.handlers.modpython > SetEnv DJANGO_SETTINGS_MODULE beijing_eats.settings > PythonInterpreter beijing_eats > PythonDebug On > > > Here's the 404 error I'm getting for: > > http://localhost/beijingeats/* > > > Page not found (404) > Request Method: GET > Request URL: http://localhost/beijingeats/admin/ > > Using the URLconf defined in beijing_eats.urls, Django tried these URL > patterns, in this order: > >1. ^media/([^/]+)$ >2. ^restaurant/([^/]+) >3. ^admin/ > > The current URL, /beijingeats/admin/, didn't match any of these. > > You're seeing this error because you have DEBUG = True in your Django > settings file. Change that to False, and Django will display a > standard 404 page. > > > > -- --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
extends admin/change_list.html bug?
Hi, I created a page that {% extends "admin/change_list.html" %} Everything is working fine except, for some reason, the page doesn't show the links in {% block userlinks %} when I use apache but it *does* show them when I use the development server. The code is exactly the same on both setups. These are the 'documentation, change password, logout' links you see on any standard admin page, and I *do* see them on admin pages on my apache setup. The apache setup does find the admin css stuff fine so I don't think that the apache configuration could be the problem. Also, I can customize admin/base.html just fine. Any ideas what could be going on? I am using svn 5559. Thanks, Vincent On 6/29/07 1:56 PM, "Matthew Nuzum" <[EMAIL PROTECTED]> wrote: > > Just wondering if there's any additional information I can give that > might help get some suggestions on this topic. I'd really love to get > some advice. > > On Jun 28, 4:30 pm, Matthew Nuzum <[EMAIL PROTECTED]> wrote: >> So here it is:http://webapps.ubuntu.com/course_locator/ >> >> Click on Canada, and see what would ideally be a cross tab. >> >> The problem is, I'd like to have the event dates for training events >> for the same course in the same town on the same row (notice that >> several rows there differ only in the fact that the training date is >> in August instead of July). I know how to do this in SQL just fine, >> but as I've found, the SQL way is not always the ideal way in Django. >> >> I'm happy to share my model and view code, but just imagine a non- >> normalized, ultra-simple model, and that's what I've done. (two >> models, Partners and Events) >> >> The end goal is to display all events in the next three months for a >> given country. >> >> Can anyone share some suggestions on how to get a cross tab the Django >> way? > > > > -- --~--~-~--~~~---~--~~ 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: Variables available to all templates
Do you want to show the user all your content without authentication? Why not just use @login_required decorator to have then login when needed? Below are the commands you need. from django.contrib.auth.decorators import login_required @login_required def myfunction(request): # do stuff Vincent On 6/28/07 4:51 PM, "Kirk Strauser" <[EMAIL PROTECTED]> wrote: > > Is there a list of variables that all templates can access? I'm > asking out of general interest, but the problem I'm trying to solve is > that I want to have a "login" or "logout" link on every page of the > site, depending on whether a visitor is currently authenticated, and I > don't want to have to pass in { 'username': request.user.username } in > every single view. Is there a django-ish way to do this? > > > > -- Vincent R. Nijs Assistant Professor of Marketing Kellogg School of Management, Northwestern University 2001 Sheridan Road, Evanston, IL 60208-2001 Phone: +1-847-491-4574 Fax: +1-847-491-2498 E-mail: [EMAIL PROTECTED] Skype: vincentnijs --~--~-~--~~~---~--~~ 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: Customize change_list using a filter
If you want to use the admin page, you can add the following into your model class. class Admin: list_display('cars') list_filter = ('cars') If you want to create a custom page outside of admin then it is a little more difficult (for me at least :) ). I made a page like that last week. I can send you the code if you are interested. Best, Vincent ~ On 6/28/07 9:43 AM, "Diego" <[EMAIL PROTECTED]> wrote: > > Hi, I'm using the admin interface, I need use a change_list.html > filtered. > Example: > Show only Ford cars > Any ideas to do that?? > > Regards > > > > -- Vincent R. Nijs Assistant Professor of Marketing Kellogg School of Management, Northwestern University 2001 Sheridan Road, Evanston, IL 60208-2001 Phone: +1-847-491-4574 Fax: +1-847-491-2498 E-mail: [EMAIL PROTECTED] Skype: vincentnijs --~--~-~--~~~---~--~~ 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: How can I rename uploaded files to a random filename?
If you just want to upload some files you might do something like the following. The save function uses plain python to save the files to the FILE_UPLOAD_DIR you defined in your setting file. You can play around with the file names as much as you want here. Question: Why a random name? Vincent class Application_files(forms.Form): cv = forms.Field(label = 'CV *', widget = forms.FileInput(), help_text="pdf or Word document") paper = forms.Field(label = 'Paper *', widget = forms.FileInput(), help_text="pdf or Word document") def save(file,key,user,ext,overwrite=True): if ext in ['pdf','doc']: f = open('%s%s_%s.%s' % (settings.FILE_UPLOAD_DIR,key,user,ext,),'wb') f.write(file) f.close() def apply(request): if request.POST: for i in request.FILES.keys(): ext = request.FILES[i]['filename'][-3:].lower() file = request.FILES[i]['content'] save(file,i,request.user,ext.lower()) else: form = Application_files() return render_to_response('apply/apply.html',{'form':form,}) On 6/26/07 10:43 PM, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote: > > On 6/25/07, rob <[EMAIL PROTECTED]> wrote: >> >> We upload all of our images via the Admin app and would like all >> uploaded images to be renamed to a set of numbers. We can generate the >> random numbers fine, but is there an easy way to rename the file once >> it's uploaded in the Admin app? > > Not at present. You would need to write a customized FileField to > implement this sort of behaviour. > > Yours, > Russ Magee %-) > > > -- Vincent R. Nijs Assistant Professor of Marketing Kellogg School of Management, Northwestern University 2001 Sheridan Road, Evanston, IL 60208-2001 Phone: +1-847-491-4574 Fax: +1-847-491-2498 E-mail: [EMAIL PROTECTED] Skype: vincentnijs --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Custom admin view - sorting, filters, and search
The admin change list pages you get 'for free' when you add: class Admin: list_display = ( ... ) list_filter = ( ... ) search_fields = ( ... ) to your model are really nice. I'd like to add these features to my custom admin pages as well. I am getting part of the way there to sort the data shown in a template by clicking the column header of a data table but even that is still very clunky. Does anyone have any examples of how to add one or more of these components to a template that extends admin/base_site.html and the associated views.py? Thanks, Vincent --~--~-~--~~~---~--~~ 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: CSS on dev server, same old problem
I think it should work if you use: (r'^appsmedia/(?P.*)$', 'django.views.static.serve', {'document_root': '/nobackup/reis/Project/Manager/templates/ appsmedia'}), On the template: Or (r'^manager/appsmedia/(?P.*)$', 'django.views.static.serve', {'document_root': '/nobackup/reis/Project/Manager/templates/ appsmedia'}), On the template: This is what I used: (r'^site_media/(?P.*)$', 'django.views.static.serve', {'document_root': '/home/user/django/project/site_media'}), Works fine. Vincent On 6/18/07 3:29 AM, "AnaReis" <[EMAIL PROTECTED]> wrote: > > > > On Jun 15, 5:22 pm, alg <[EMAIL PROTECTED]> wrote: >>> >> I can see the css files code on the web browser >>> through:http://145.23.6.135:8000/manager/appsmedia/css/css1.css >> >> You're using an absolute path in the link element's href. > > Hum... How do I use a dynamic path? (Sorry if it's a lame question...) > > > > -- Vincent R. Nijs Assistant Professor of Marketing Kellogg School of Management, Northwestern University 2001 Sheridan Road, Evanston, IL 60208-2001 Phone: +1-847-491-4574 Fax: +1-847-491-2498 E-mail: [EMAIL PROTECTED] Skype: vincentnijs --~--~-~--~~~---~--~~ 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: App.objects.get(user='John') error
Thanks! That works. Vincent On 6/14/07 3:32 PM, "Iapain" <[EMAIL PROTECTED]> wrote: > > Of course it'll give you error, suppose your User is > > class User(models.Model): > first_name = models.CharField(maxlength=256) > > class App(models.Model): >user = models.ForeignKey(User, unique=True, editable=False) > > then use: > try: > user_exists = Application.objects.get(user__first_name='john') > except Application.DoesNotExist: > #whatever you want here > > Cheers, > Deepak > > On Jun 15, 12:20 am, Vincent Nijs <[EMAIL PROTECTED]> > wrote: >> Hi, >> >> I have the following model >> >> class App(models.Model): >> user = models.ForeignKey(User, unique=True, editable=False) >> >> In a view I now want to check if a user is indeed in the database table. I >> tried the following >> >> user_exists = Application.objects.get(user='john') >> >> But this give the following error: >> >> invalid input syntax for integer: "john" >> >> Any ideas on how to do this check? >> >> Thanks, >> >> Vi ncent > > > > -- Vincent R. Nijs Assistant Professor of Marketing Kellogg School of Management, Northwestern University 2001 Sheridan Road, Evanston, IL 60208-2001 Phone: +1-847-491-4574 Fax: +1-847-491-2498 E-mail: [EMAIL PROTECTED] Skype: vincentnijs --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
App.objects.get(user='John') error
Hi, I have the following model class App(models.Model): user = models.ForeignKey(User, unique=True, editable=False) In a view I now want to check if a user is indeed in the database table. I tried the following user_exists = Application.objects.get(user='john') But this give the following error: invalid input syntax for integer: "john" Any ideas on how to do this check? Thanks, Vincent --~--~-~--~~~---~--~~ 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: form_for_model + FileField issue
Malcolm, I wasn't very clear in my question. Sorry about that. It took a bit of trial and error but I found a hack that works the way I want it to. I use the model and form_for_model/form_for_instance for all fields except the file uploads. For the file uploads I use FileInput(). That was what I meant by '... I could leave the FileFields out of the model and use a form class for those fields instead.' I you have any suggestions on how to secure/improve/validate this please let me know. Thanks, Vincent class files(forms.Form): file1 = forms.Field(widget = forms.FileInput()) file2 = forms.Field(widget = forms.FileInput()) def save(file,key,user,ext): if ext in ['pdf','doc']: f = open('%s%s_%s.%s' % ('/home/myhomedir/',key,user,ext,),'wb') f.write(file) f.close() @login_required def submit(request): try: # show previous input if available inst = Application.objects.get(user=request.user) ApplicationForm = form_for_instance(inst) except: # else create an empty form ApplicationForm = form_for_model(Application) if request.POST: form1 = ApplicationForm(request.POST) if form1.is_valid(): form1.cleaned_data entry = form1.save(commit=False) entry.user = request.user entry.save() # save files attached to the form pfile = request.POST.copy() pfile.update(request.FILES) form2 = files(pfile) for i in request.FILES.keys(): ext = request.FILES[i]['filename'][-3:] file = request.FILES[i]['content'] save(file,i,request.user,ext) # confirm data is submitted return render_to_response('submit/thankyou.html') else: form1 = ApplicationForm() form2 = files() return render_to_response('submit/submit.html',{'form1':form1,'form2':form2,}) TEMPLATE # Form {{ form1.as_table }} {{ form2.as_table }} On 6/12/07 8:12 PM, "Malcolm Tredinnick" <[EMAIL PROTECTED]> wrote: > > On Tue, 2007-06-12 at 20:03 -0500, Vincent Nijs wrote: >> Thanks for the reply Malcolm. >> >> That is too bad. I noticed that the FileFields do have a browse button in >> the admin form btw. Do they not use form_for_model? >> >> As an alternative, is there a way to use FileField 's separately from the >> the form_for_model fields? I am thinking I could leave the FileFields out of >> the model and use a form class for those fields instead. Not sure how to get >> this done however. Any suggestions/examples? > > Your questions don't really make sense. There is no FileField in > newforms yet. The current admin interface does not use newforms, so it > isn't pertinent to the issue. > > Do not get model fields and form fields confused, since they are > entirely different objects serving different purposes. You certainly > cannot chop and change them. > > Regards, > Malcolm > > > > > -- Vincent R. Nijs Assistant Professor of Marketing Kellogg School of Management, Northwestern University 2001 Sheridan Road, Evanston, IL 60208-2001 Phone: +1-847-491-4574 Fax: +1-847-491-2498 E-mail: [EMAIL PROTECTED] Skype: vincentnijs --~--~-~--~~~---~--~~ 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: form_for_model + FileField issue
Thanks for the reply Malcolm. That is too bad. I noticed that the FileFields do have a browse button in the admin form btw. Do they not use form_for_model? As an alternative, is there a way to use FileField 's separately from the the form_for_model fields? I am thinking I could leave the FileFields out of the model and use a form class for those fields instead. Not sure how to get this done however. Any suggestions/examples? Thanks, Vincent On 6/12/07 7:51 PM, "Malcolm Tredinnick" <[EMAIL PROTECTED]> wrote: > > On Tue, 2007-06-12 at 18:50 -0500, Vincent Nijs wrote: >> Hi, >> >> I have a form linked to a model. I am using form_for_model or >> form_for_instance as required. >> >> The only issue is that FileField fields are not displayed with a 'browse' >> button. The function I am using is given below. >> >> I know from the documentation that model fields get converted to form fields >> by form_for_model (e.g., FileField to CharField). >> >> But I want a FileField in my form :) > > How to handle file uploads correctly and neatly in newforms is still > under development. Some results are in ticket #3297, although there will > be a hiatus in that work for a few weeks since Russell is away. > > 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
form_for_model + FileField issue
Hi, I have a form linked to a model. I am using form_for_model or form_for_instance as required. The only issue is that FileField fields are not displayed with a 'browse' button. The function I am using is given below. I know from the documentation that model fields get converted to form fields by form_for_model (e.g., FileField to CharField). But I want a FileField in my form :) Is there a way around this? Or another way to create the form linked to the model that does not use form_for_model or form_for_instance? Thanks, Vincent def submit(request): try: inst = Application.objects.get(user=request.user) ApplicationForm = form_for_instance(inst) except: ApplicationForm = form_for_model(Application) if request.POST: form = ApplicationForm(request.POST) if form.is_valid(): form.cleaned_data entry = form.save(commit=False) entry.user = request.user entry.save() return render_to_response('submit/thankyou.html') else: form = ApplicationForm() return render_to_response('submit/submit.html',{'form':form,}) --~--~-~--~~~---~--~~ 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: Adding a group, and users to that group
Thanks for the help Russ: That worked. Next problem :) I want to add users to a group. g = Group.objects.get(name='section81') gives errors. If I could get that to work I'd want to add a user to that group: u = User.objects.get(username='doe') This also give errors. Finally: u.groups.add(g) Which doesn't work because the previous 2 didn't :) Sorry to ask multiple questions about this but I can't seem to find any clear documentation on this. Vincent On 6/7/07 12:55 AM, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote: > > On 6/7/07, Vincent Nijs <[EMAIL PROTECTED]> wrote: >> >> TypeError: create() takes exactly 1 argument (2 given) >> >> Any ideas? > > Calling > g = Group.objects.create("section81") > > is the same as calling > > Group("section81") > > This yeilds an error because there is no way of knowing which model > field the string "section81" should be applied to. > > If you make this a keyword argument: > > g = Group.objects.create(name="section81") > > the problem should resolve itself. > > Yours, > Russ Magee %-) > > > -- Vincent R. Nijs Assistant Professor of Marketing Kellogg School of Management, Northwestern University 2001 Sheridan Road, Evanston, IL 60208-2001 Phone: +1-847-491-4574 Fax: +1-847-491-2498 E-mail: [EMAIL PROTECTED] Skype: vincentnijs --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Adding a group, and users to that group
Hi, I am trying to create a group so that I can then add users to that group. I tried the following which is very similar to how you create users. from django.contrib.auth.models import Group g = Group.objects.create('section81') However this give the following error: exceptions.TypeErro Traceback (most recent call last) TypeError: create() takes exactly 1 argument (2 given) Any ideas? Thanks, Vincent On 6/7/07 12:04 AM, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote: > > On 6/7/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> >> Hi Everyone, >> I'm trying out django and it's been really easy getting the auth >> library up and running. I hit an issue where I want to login a new >> user right after they've registered and take them to their profile >> page. >> >> I tried calling the auth.login method but I got an error saying that >> the new_user object doesn't have the attribute error. I guess this is >> because the session and auth middlewares didn't get to alter new_user. >> >> Does django provide a quick way of resolving this? > > Yes. The 'backend' attribute that is being complained about is an > attribute that is decorated onto the user object by the authenticate() > method (django.contrib.auth.authenticate()). If you call authenticate, > providing the login credentials, you will get a 'decorated' user that > can then be used in the login method. > > Yours, > Russ Magee > > > -- Vincent R. Nijs Assistant Professor of Marketing Kellogg School of Management, Northwestern University 2001 Sheridan Road, Evanston, IL 60208-2001 Phone: +1-847-491-4574 Fax: +1-847-491-2498 E-mail: [EMAIL PROTECTED] Skype: vincentnijs --~--~-~--~~~---~--~~ 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: Form input to csv + file upload
I have been searching for examples but everything that I see has a link to a database. How to you 'get' the data from a form in django? What is the equivalent of 'data = cgi.FieldStorage(keep_blank_values=1)' I would use with a Python cgi script? Thanks, Vincent On 6/5/07 7:22 PM, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote: > > On 6/6/07, Vincent Nijs <[EMAIL PROTECTED]> wrote: >> >> Question: If I want to save the file to a directory and information about >> the submitter (e.g., name and time of submission) directly to a csv file, >> how would I do that in Django? Do you need 'newforms' to do that? In the >> documentation it seems that if you use newforms you would have to save >> everything to a database. Is that really necessary? For some of my forms I >> want to save information in a dbase that but probably not for all. > > Newforms is a tool for constructing HTML forms. One obvious source of > forms is to create a form that matches a database object, so newforms > provides tools to assist in creating forms for database objects, with > an easy method for saving objects that are created/modified using that > form. However, forms don't have to be bound to a database object. You > can create a form, gather data using that form, and then just use the > data, rather than using it to populate a database object. > > It looks like what you need to do is: > - write a custom form that gathers the data you need > - write a custom view that displays the form, validates the data, then > outputs the CSV file if the form data is valid. > > Yours, > Russ Magee %-) > > > -- Vincent R. Nijs Assistant Professor of Marketing Kellogg School of Management, Northwestern University 2001 Sheridan Road, Evanston, IL 60208-2001 Phone: +1-847-491-4574 Fax: +1-847-491-2498 E-mail: [EMAIL PROTECTED] Skype: vincentnijs --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Form input to csv + file upload
Below is an example of the type form I used to process with a python cgi script. Now I am trying to move everything over to Django. Question: If I want to save the file to a directory and information about the submitter (e.g., name and time of submission) directly to a csv file, how would I do that in Django? Do you need 'newforms' to do that? In the documentation it seems that if you use newforms you would have to save everything to a database. Is that really necessary? For some of my forms I want to save information in a dbase that but probably not for all. I am getting the hang of templates and authentication in Django but forms look a bit more complicated. Thanks, Vincent Name: John Sue Assignment: Assignment 1 Assignment 2 Word document: --~--~-~--~~~---~--~~ 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: include statements for non-dynamic pages
Russell, I think I am starting to get the basic idea of 'extends' for templates. However, I don't get what I need to do to get my basic example (or your example for that matter) to generate the page I want to see in my browser. It doesn't just work the way php would here so I am guessing I need to add a 'view' or do something with 'urls.py' or both but I can't figure out what that would be since I am not processing anything or sending any information to the page. Thanks, Vincent On 5/28/07 7:39 PM, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote: > > On 5/29/07, vince <[EMAIL PROTECTED]> wrote: >> >> What would i need to do exactly to >> get the following to work? >> >> {% include("design/index_nav.html") %} >> Welcome to the home page >> {% include("design/footer.html") %} > > The following would work: > > {% include "design/index_nav.html" %} > Welcome to the home page > {% include "design/footer.html" %} > > But this probably isn't the best way to solve the problem. A better > approach is to use blocks and extend. > > design/base.html: > - > {% block nav %} > Some navigation content > {% endblock %} > {% block content %} > {% endblock %} > {% block footer %} > Some footer content > {% endblock %} > > > design/home.html > - > {% extends "design/base.html" %} > {% block content %} > Welcome to the home page > {% endblock %} > > That way, you set up a single page template (base.html), with a block > where you want various significant pieces of content (main content, > sidebar, etc), and then on your actual content page, you replace > specific blocks. > > This way, you ensure that every page on your site is using a common > basic template. If you need to, you can even layer ther extensions > (e.g., base -> content -> home) to add complexity to your basic > templates in layers. > > See [1] for more details on how template inheritance works. > > [1] http://www.djangoproject.com/documentation/templates/#template-inheritance > > Yours, > Russ Magee %-) > > > -- Vincent R. Nijs Assistant Professor of Marketing Kellogg School of Management, Northwestern University 2001 Sheridan Road, Evanston, IL 60208-2001 Phone: +1-847-491-4574 Fax: +1-847-491-2498 E-mail: [EMAIL PROTECTED] Skype: vincentnijs --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---