|
MetaKnyght posted:I've searched for information on this, but can't really seem to find anything useful. I think my Google-fu has gotten weak. Well, consider that a Web framework is inherently limited to responding to browser requests and I think you'll realize why a script run by a cron job is the way to go here All you should have to do for a Python script to load up your Django models/views/whatever, is to ensure the cron has DJANGO_SETTINGS_MODULE set, just like you have to do for your Web server that hooks into Django. E.g. for a nightly cron task in the root crontab, code:
What I've seen done in the Rails world, and it makes some sense, is to construct a static HTML page that lives outside your Apache docroot somewhere, and to symlink it into the docroot while you need the site to be down (i.e. your cron job script would take care of putting it up, then taking it down at the end). You then pair that with some Apache rewrite rules/conditions which essentially say "if this file exists, redirect any and all requests to it". End result is that when that symlink exists, Apache sends all traffic to that "lol we're updating sorry!" page, and once your process is done and the symlink is removed, the site goes back to normal. bitprophet fucked around with this message at 20:25 on Feb 14, 2009 |
# ? Feb 14, 2009 20:20 |
|
|
# ? May 15, 2024 01:30 |
|
bitprophet posted:Unless you're doing something really funky with your PythonPath when Django loads up, Django is just Python, and should always have full access to anything on your global PythonPath. I think you figured it out. I have two installs of Python, 2.4 and 2.5. Sorry I forgot to put the necessary information. I'm on Windows XP and I just used the installers for everything.
|
# ? Feb 14, 2009 22:58 |
|
Crazak P posted:I think you figured it out. I have two installs of Python, 2.4 and 2.5. Sorry I forgot to put the necessary information. I'm on Windows XP and I just used the installers for everything. Yea, that would do it. If you find aforementioned lib/site-packages dir, it should be inside some directory hierarchy which, at some point, mentions the Python version, i.e. C:\something_or_other\Python2.4\Lib\Site-Packages. You likely have two identical trees like this, one for Python2.4 and one for Python2.5. I don't use Windows so I can't help you with the specifics, but your various configs for Apache or Django or the command line Python binary, should all be pointing at one or the other of the two versions; you want to try and make sure that everything is using 2.5 if possible (or at least make sure they are consistent; 2.5 is better because it's newer). Or, ideally, just remove Python 2.4, if there's an uninstaller that will target just that version.
|
# ? Feb 15, 2009 03:49 |
|
I was wondering if anyone knew how to do a simple for loop that iterates the number it gets from say "bingodingo.number". I've searched djangoproject.com and found a ticket about it. I can't seem to find any documentation on how to make the for loops in django work like that
|
# ? Feb 18, 2009 22:55 |
|
hitze posted:I was wondering if anyone knew how to do a simple for loop that iterates the number it gets from say "bingodingo.number". I've searched djangoproject.com and found a ticket about it. I can't seem to find any documentation on how to make the for loops in django work like that This is more to do with python than with Django its self, in python you are encouraged to loop through all elements of a list (or in Django a query result set) instead of using an iterator (as I'm sure you've found). So first I'd look at avoiding this in some way. However, if you want to perform a loop x times you could use something like the built-in xrange function in your view. Then pass the resulting xrange object to your template. code:
Wedge of Lime fucked around with this message at 23:42 on Feb 18, 2009 |
# ? Feb 18, 2009 23:38 |
|
MetaKnyght posted:I've searched for information on this, but can't really seem to find anything useful. I think my Google-fu has gotten weak. Your second question is pretty hard. There are a few ways to skin this cat and the first thing that pops in my head is to have a DB table that has a "lock" boolean to be true when the cron is running and use a decorator around views that alter the DB. So when a view is called alters the DB you can redirect to a polite message to try again in a bit. Unfortunately this isn't a good user experience. I'm not sure of the exact situation that your working in that needs a full lock on the tables but, there's few options to really use here. If your user experience is critical and you don't want 1 minute down times (which is essentially what your doing) every 15 minutes you need to refactor this somehow. Is there anyway you can simple store up an array of updates that you want to do as your analyzing your data and then run through them while locked as opposed to locking doing all the queries analysis and updating then unlocking, etc...
|
# ? Feb 19, 2009 02:39 |
|
2 pieces to the puzzle, 1 a management command for the script itself, 2 python lockfile for the lock: http://pypi.python.org/pypi/lockfile
|
# ? Feb 19, 2009 15:36 |
|
Washington Times just released some pretty awesome django projects: http://opensource.washingtontimes.com/blog/post/coordt/2009/02/washington-times-releases-open-source-projects/ edit: Forgot to mention that I started playing with django-projectmgr and it is pure awesome. deimos fucked around with this message at 02:05 on Feb 20, 2009 |
# ? Feb 20, 2009 01:24 |
|
deimos posted:Washington Times just released some pretty awesome django projects: I saw the feature list for that and basically creamed myself, it's got a LOT of ideas I was hoping to put into a tiny fledgling Django app I have going in the same vein. Plan to check out the source sometime soon.
|
# ? Feb 20, 2009 04:08 |
|
As a sidenote, what's the state of django on Windows? I haven't tried it at all. I need to connect to SQL Server and last I checked the only reliable way was running django on Windows through Apache and mod_python.
|
# ? Feb 20, 2009 06:30 |
|
deimos posted:As a sidenote, what's the state of django on Windows? I haven't tried it at all. I need to connect to SQL Server and last I checked the only reliable way was running django on Windows through Apache and mod_python. Get a WSGI plugin for IIS or Apache.
|
# ? Feb 20, 2009 06:53 |
|
deimos posted:As a sidenote, what's the state of django on Windows? I haven't tried it at all. I need to connect to SQL Server and last I checked the only reliable way was running django on Windows through Apache and mod_python. On the MSSQL front django-pyodbc and django-mssql are both decent, though I don't know which is actually better.
|
# ? Feb 20, 2009 14:01 |
|
Anyone got any recomendations for database schema migration tools for Django? Anyone use and are happy with it? I'm talking about the sort of tool that allows me to type "manage.py evolvedb" and it will print SQL to sync the differences between the models and the DB structure.
|
# ? Feb 20, 2009 14:15 |
|
Mashi posted:Anyone got any recomendations for database schema migration tools for Django? Anyone use and are happy with it? I'm talking about the sort of tool that allows me to type "manage.py evolvedb" and it will print SQL to sync the differences between the models and the DB structure. I like django-evolution: http://code.google.com/p/django-evolution/ south is also popular: http://south.aeracode.org/
|
# ? Feb 20, 2009 15:45 |
|
I've used django-evolution.. worked well for what I used it for (really simple migrations.. adding / removing db columns). Didn't need to get into anything too advanced.
|
# ? Feb 20, 2009 16:29 |
|
django templating question: How do I insert some html after every third iteration through a loop? example: code:
|
# ? Feb 20, 2009 21:15 |
|
Crazak P posted:django templating question: edit: see the post below this for a much better answer! tankadillo fucked around with this message at 23:47 on Feb 20, 2009 |
# ? Feb 20, 2009 21:25 |
|
code:
|
# ? Feb 20, 2009 23:17 |
|
king_kilr posted:On the MSSQL front django-pyodbc and django-mssql are both decent, though I don't know which is actually better. I can tell you from experience that pyodbc is the best free MSSQL driver for python, and that django-mssql is Windows-only (it requires PyWin32). I've never developed against either, though.
|
# ? Feb 21, 2009 00:28 |
|
king_kilr posted:code Awesome, thanks man. I knew I had to use divisbleby somewhere, but I was thinking more along the lines of declaring a variable, which I don't think you can using the template language.
|
# ? Feb 21, 2009 03:34 |
|
Crazak P posted:Awesome, thanks man. I knew I had to use divisbleby somewhere, but I was thinking more along the lines of declaring a variable, which I don't think you can using the template language. The loop variables are really great, make sure you learn them because they're very useful here.
|
# ? Feb 21, 2009 05:18 |
|
I completely missed that while looking through the documentation.
|
# ? Feb 21, 2009 05:29 |
|
bitprophet posted:I saw the feature list for that and basically creamed myself, it's got a LOT of ideas I was hoping to put into a tiny fledgling Django app I have going in the same vein. Plan to check out the source sometime soon. The source is gorgeous. It's really clean code and from what I have browsed so far, I've already learned a couple of new things. You actually need to dive into the code to see some of the really neat stuff it does like notifications using django-notification. Ohh and MPTT is my new most favorite thing ever. deimos fucked around with this message at 05:45 on Feb 21, 2009 |
# ? Feb 21, 2009 05:30 |
|
This is probably an easy problem to solve, but I haven't seen anything helpful yet. Basically I have a base template that several views use, and there are a few variables that I want to always get passed to that template. Right now I just include them in my render_to_response() function at the end of each view, but it seems like there would be an easier way that didn't require repeating code.
|
# ? Feb 21, 2009 06:05 |
|
raezr posted:This is probably an easy problem to solve, but I haven't seen anything helpful yet. Basically I have a base template that several views use, and there are a few variables that I want to always get passed to that template. Right now I just include them in my render_to_response() function at the end of each view, but it seems like there would be an easier way that didn't require repeating code. You probably want to write a custom context processor, which is just a function that can add key/value pairs to the context dict. Basics of how to enable context processors in general: http://docs.djangoproject.com/en/dev/ref/templates/api/#id1 How to write your own context processors: http://docs.djangoproject.com/en/dev/ref/templates/api/#writing-your-own-context-processors Only caveat is that, as in the first link, you need to ensure that you render templates with that special RequestContext class for the processors to work. (You can write a one-line function to replace render and/or render_to_response, that uses RequestContext, if you find yourself needing your context processor across the entire site.)
|
# ? Feb 21, 2009 14:12 |
|
bitprophet posted:You probably want to write a custom context processor, which is just a function that can add key/value pairs to the context dict.
|
# ? Feb 22, 2009 03:26 |
|
I just finished setting up this (post save?) deal. It renames the photo and moves it into a new folder and it updates the photos path. Everything seems to work properly with it, adding a new entry, and editing an existing one.code:
|
# ? Feb 22, 2009 23:37 |
|
I've got a question about template inheritance. I have a common setup, one parent template for the site header / footer, and another one that extends it for the section content. What I want to do is have the parent template include another template for the login block. There isn't an elegant way to do it using normal inheritance, it would have to go "section extends login extends site_outer", which is wrong. To demonstrate in markup: code:
|
# ? Feb 26, 2009 14:55 |
|
Mashi posted:{# this is where I want login.html included #} Sounds like you want to {% include login.html %}
|
# ? Feb 26, 2009 15:19 |
|
Git posted:Sounds like you want to {% include login.html %} Yes.. I don't know how I missed that. Thank you.
|
# ? Feb 26, 2009 15:36 |
|
I'm using Django with Google App Engine and I can't seem to figure out how to display a specific element from a list, when the element index is contained in another variable. I have a list called contentType. It's a simple list with elements 0 through 4. I have a variable (I guess a dict?) called adventure. It's from my datamodel and has a property called contentType, so adventure.contentType is the integer of the index I want to display. I basically want this: contentType[adventure.contentType] But that doesn't work. I can't figure what does. I tried {{ contentType|splice:"3:"|first }} This works and gives me back the 4th element. When I changed it to {{ contentType|splice:"adventure.contentType:"|first }} it just gives me back the 1st element. I can also do {{ contentType.3 }}, which gives me back the 4th element. How can I use a variable there instead of hard coding the number? I guess I could just do this little bit of logic in the python and pass that variable into the template but it seems like there should be a way to do it here, in the template.
|
# ? Mar 1, 2009 12:35 |
|
Another question: I'd like to build a quick and dirty administration tool for 3 database tables with foreign keys to each other. It's a pretty standard relationship. The database is oracle, and the tables are already created by our database admins. I only have read and write access to it, not any admin permissions. What do I do at this point, in regards to the data model? Do I just setup my data model to mimic what already exists? Will Django just start reading and writing to it without it actually running in any SQL code to modify the tables?
|
# ? Mar 4, 2009 07:02 |
|
tayl0r posted:Another question: You still have to generate the models.py file for an application then fire up your app. You can either do it by hand or use a built in Django tool. I recommend a bit of both Configure all your database settings like normal (DATABASE_NAME, etc) then run python manage.py inspectdb > appname/models.py and Django will automatically construct the models.py file for you in your application. I highly recommend going into that models file and just checking it to make sure that it actually makes sense and has identified the relationships correctly. If you run syncdb after this thought Django will add some tables to your database for user administration and permissions like it always does for every app.
|
# ? Mar 4, 2009 15:35 |
|
Oh nice, I didn't realize it had an inspectdb command. I will get on that. Hopefully I can limit it to just the couple of tables I want to mess with, and not all 50+ of them. Thanks! --- edit --- drat, looks like this isn't quite going to work, since the tables I want to work with are in other schemas (not mine). I'm going to setup the synonyms but that will break the management tools apparently, which is what I wanted to use. http://code.djangoproject.com/ticket/6148 "There is frequently a need for Django to access data from tables in other schemas; this is especially true when building Django apps on top of legacy databases. A current workaround in Oracle is to manually create private synonyms inside the Django schema, referencing the necessary tables from other schemas. However, the management commands do not currently recognize the existence of synonyms via introspection. Additionally, the synonym solution may not be sufficiently generic in the long term." tayl0r fucked around with this message at 18:51 on Mar 4, 2009 |
# ? Mar 4, 2009 17:30 |
|
In a site I'm making I have a model called Feed. Some types of content are associated with a Feed, and the name of the feed is prefixed to every path on the site (ie /feed1/whatever). When a user makes a request I have to determine the feed they are requesting by looking at request.path. That then needs to be stored somewhere so it can be added to template context and made available to models (I really want to have managers that pick it up automatically). Since this is per request data, it makes sense to store it as a property of the request, but this is less than ideal because then I can't have model managers that pick it up automatically. If I store it as a property of the settings module then sometimes I can't access it later. The most basic way to do it is to match the feed in the URLs and pass it in to every view, but then there needs to be boilerplate code in every view. It is the simplest way though. It would be nice to be able to match it in the URLConf, pass it to a function which stores it, then pass execution back to the urlresolvers. Anyone have suggestions / preferred methods of doing something like this? Mashi fucked around with this message at 13:03 on Mar 5, 2009 |
# ? Mar 5, 2009 03:39 |
|
So I have the Django admin tools and data model definitions setup and it works pretty well, even though I'm using Oracle and my tables are in different schemas. The synonym trick seems to work. The only problem I'm having is with one of my tables that has a primary key of 2 columns. code:
code:
Any ideas? edit- gently caress. another thing that isn't supported out of the box! "Currently, you can "fake" it by declaring one of the keys to be primary in Django and adding a unique constraint to the model. You'd have to do without the auto-generated SQL that Django gives you, but if you're smart enough to know how and why to use multiple primary keys, you can probably write the schema by hand. Still, this is less than ideal." http://code.djangoproject.com/ticket/373 tayl0r fucked around with this message at 23:00 on Mar 6, 2009 |
# ? Mar 6, 2009 22:50 |
|
When using mod_wsgi in daemon mode with apache, should i feel comfortable running multiple threads? I don't know how to check my application for thread safety any further than just doing a bit of stress testing and seeing if it falls over. It's a basic database driven Django site without any special 3rd party modules. I'm asking because I always see setup tutorials showing examples where there is a thread count of 15 or 25, and sometimes not warning that the application should be checked for thread safety first.
|
# ? Mar 8, 2009 02:01 |
|
I just started working on a Django based site and I was wondering what the best practices are for using jQuery based AJAX with Django?
|
# ? Mar 8, 2009 04:41 |
|
Mashi posted:When using mod_wsgi in daemon mode with apache, should i feel comfortable running multiple threads? I don't know how to check my application for thread safety any further than just doing a bit of stress testing and seeing if it falls over. It's a basic database driven Django site without any special 3rd party modules. The threads can't share anything, so you shouldn't have a problem. The option is available more as a matter of performance. The only time I could imagine it being an issue is if you're using a C extension that isn't coded properly. Issues with concurrent access to shared resources outside of Python would also present themselves using multiple processes, so you should keep that in mind if you're doing anything like that (e.g., modifying files, in which case you'd use file locks). I haven't had any issues doing this with Django and MySQLdb.
|
# ? Mar 8, 2009 04:51 |
|
|
# ? May 15, 2024 01:30 |
|
Milde posted:The threads can't share anything, so you shouldn't have a problem. The option is available more as a matter of performance. Great. I'm gonna give it a shot, then. Ned posted:I just started working on a Django based site and I was wondering what the best practices are for using jQuery based AJAX with Django? Here's one I do: When I have a clickable element that can update the page via ajax, I use a normal link with an event handler that returns false. If the client has javascript, the return false in the event handler will stop the client from following the link. I use the same view for ajax and normal requests, but I detect if the request is an ajax request and return the same data either in JSON or a normal template. Perhaps if the request is an ajax request you can skip some context processors that won't be required, since the whole page is not reloading.
|
# ? Mar 8, 2009 05:44 |