|
Use the template inheritance functionality along with the auth context manager. First off, in your settings.py, check that django.core.context_processors.auth is in the variable TEMPLATE_CONTEXT_PROCESSORS. Then in every view, give it a request context like this.code:
Once you've done that, you can do stuff like code:
hey mom its 420 fucked around with this message at 18:17 on Jul 8, 2008 |
# ? Jul 8, 2008 18:13 |
|
|
# ? May 16, 2024 11:48 |
|
For Django hosting, checkout Slicehost. Its just a dirtcheap vHost, and they are pretty cool guys. Select debian (naturally), apt-get up to python 2.5, follow the apache->django setup and serve django like a motherfucker. too easy. And by cheap I mean 'absurdly cheap'.
|
# ? Jul 8, 2008 18:29 |
|
duck monster posted:For Django hosting, checkout Slicehost. Its just a dirtcheap vHost, and they are pretty cool guys. Select debian (naturally), apt-get up to python 2.5, follow the apache->django setup and serve django like a motherfucker. too easy. Thats exactly the deployment set-up I plan on using +memcache I'm tagging that with AMZN S3 for static file hosting via a CNAME forward media.mydomain.com so I don't have to run lighttp or a second Apache instance. I'm hoping it flys for a time during my ramp up phase. Has anyone looked at deploying Django with mod_wsgi instead of mod_python. I've heard there are some performance benefits over mod_python but, it looks like you might have to hack your code base a bit to make it compatible. I've googled but, it's a bit sparse.
|
# ? Jul 8, 2008 19:33 |
|
webfaction seems to be decent for cheap hosting too.
|
# ? Jul 8, 2008 19:34 |
|
ATLbeer posted:Has anyone looked at deploying Django with mod_wsgi instead of mod_python. I've heard there are some performance benefits over mod_python but, it looks like you might have to hack your code base a bit to make it compatible. I've googled but, it's a bit sparse. I've set up Django with mod_wsgi in production environments, I haven't had any problems with it. There is one longstanding issue with Django's WSGI support involving PATH_INFO, but that can be worked around, and the mod_wsgi site has great documentation, including how to deal with Django specifically. mod_python is a huge piece of poo poo. It's a poorly designed framework around Apache, and you can only use it within Apache. Django abstracts it all away, but personally having dealt with it directly on many occasions, I could never see myself going back to it. I think mod_wsgi is the way to go.
|
# ? Jul 8, 2008 22:39 |
|
Milde posted:mod_python is a huge piece of poo poo. I'd be honestly interested to hear more on this -- not saying I don't believe you (it's semi well known that, maturity aside, mod_wsgi is a superior approach) but the only material I've seen repeatedly is that mod_python is simply not as efficient and/or layered as the WSGI approach. It's worked fine for the Django core team and it's worked fine for me and other Django folks, so I'm curious about stories from people who have had negative experiences with it, assuming you can go into the whys and hows and not just say "I had random problems X and Y" (i.e. be informed and not just anecdotal).
|
# ? Jul 9, 2008 00:38 |
|
Oh hey, late to the party I'm developing an in-house django application to administer and keep track of a ton of stuff, and just hit a major milestone of being to where it is feature-complete enough to start using it for real. Aside from deployment being a bit of a bitch (we have and need to use cPanel servers, joy!) I must say I absolutely love Django so far, and Python as well since I'm new to Python. I tried RoR a few times but it never quite "clicked" and I couldn't figure out what was going on; I'd have an idea for something I'd want to do but staring at a blank project template I had no idea where to go there. Django clicked almost immediately, and I was even able to follow along the tutorial and figure out how to change the poll application into the beginnings of the project I now have working great, and surprisingly minimal "oh god that was a dumb noob way to do that" moments that tend to be easy to fix. So far I really love how much faster it is to make better things than in, well, been using mostly PHP so far. Mostly I like how it is usually easier to and it usually "defaults" to the best practice of doing things, so even when I'm developing under a time crunch I don't feel like I'm making compromises. They really did nail that whole "perfectionists with deadlines" thing. My app makes solid and judicious use of scriptaculous and TinyMCE and a few other things I had never used before, and I was surprised at how easy it was to get something rather advanced functionality-wise going very quickly. I just really hope migrations are added eventually (although this is promising, but I haven't had time to investigate it: http://www.aswmc.com/dbmigration/ ) and that there somehow becomes a way to create new views without editing and/or creating 3 files across 2 editors though maybe if I set up a proper urlconf I'd have it easier. Still, one of the only things I miss from RoR is that it'd create skeleton files and hook up wires automatically for that sort of thing. Oh and thanks for the slicehost recommendation earlier, I'm in the market for a new VPS and I had ordered one at another webhost that I totally love for my shared hosting but I've been getting dicked around pretty bad with the VPS. CentOS only (ugh), yum mysteriously missing after the first control-panel-initiated wipe but who cares it loving sucks anyway, only tolerable after a bunch of effort to use debootstrap to get Debian on it (Ubuntu hits something weird that as best I can tell is a kernel bug) and run everything from a chroot. Combine that with some billing issues slicehost solves by being cheaper, well, I hope the positive reviews I hear pan out. e: I hope mod_python doesn't suck too bad, I don't think I have much of a choice for getting cPanel to run this without me wanting to kill myself using anything else e2: The #django channel on freenode is insanely helpful, good folk there. Just be nice to Magus, he's a bit gruff but he's a saint for as helpful as he is. Space Kimchi fucked around with this message at 01:10 on Jul 9, 2008 |
# ? Jul 9, 2008 01:06 |
|
bitprophet posted:I'd be honestly interested to hear more on this -- not saying I don't believe you (it's semi well known that, maturity aside, mod_wsgi is a superior approach) but the only material I've seen repeatedly is that mod_python is simply not as efficient and/or layered as the WSGI approach. Like I said, my beef with it stems from experience with using it directly, i.e. without a framework abstracting it out of the way. When you have a system developed only for mod_python, you can only develop applications on mod_python. This makes any kind of development a huge pain because you can't do it outside of mod_python and Apache, and its code reloading isn't really predictable and doesn't work for applications installed into site-packages. When you're using it from Django this isn't really an issue, because someone did all the hard work for you already, and you don't have to do development on mod_python. The performance differences between the two modules are basically irrelevant, and I'm not sure what you mean by more "layered." WSGI is a great specification. It doesn't tie you down to any one web server, you can use whatever WSGI server you like. mod_python predates WSGI - it's archaic and unwieldy in comparison now. The author of mod_wsgi delineates some specific differences between the two modules in this mailing list post. Among more practical differences is the ability to reload specific Python applications (by updating the modification date of a WSGI script file) and the extensive options for setting resource limits on Python processes (e.g. you can reload the processes after N requests, or reload them after N seconds idle time, etc.). I also foresee the Python community moving toward mod_wsgi because of all of these reasons, and because it's still actively developed and specifically designed for a much wider array of use cases (e.g. in shared hosting environments). Other options include FastCGI/SCGI and flup, but I personally don't use flup anymore because I ran into issues with it timing out long running HTTP connections (where this wasn't an issue with other platforms). It doesn't help that flup isn't really maintained anymore, and the author hasn't responded to my bug reports. There's also no community around it, as far as I can tell.
|
# ? Jul 9, 2008 01:10 |
|
OK, I can't figure this one out. I'm trying to provide an edit profile method for users to, well, edit their profiles. This includes image uploading. The following function works great for everything except that both their uploaded image and the renamed one get saved to the system. Obviously I only want the renamed one.code:
|
# ? Jul 9, 2008 20:57 |
|
mod_python is loving terrible, unless you need to do a very small subscript of 'very wierd' apache tasks (such as rolling a http auth driver or something). I blame it almost entirely for being the reason python is not the dominant web coding language on the net. And for the loving life of me I still can't work out the caching.
|
# ? Jul 9, 2008 21:27 |
|
I'm new to django and python so go easy on me here, but what I'm trying to do is run some code whenever a model is saved to the database, although I don't know how to do that. Is there some sort of method I can overwrite when I save this particular model?
|
# ? Jul 9, 2008 22:18 |
|
Yeah, you usually do that by overwriting the save method or by using signals. The way to overwrite the save method is pretty straightforward.code:
hey mom its 420 fucked around with this message at 22:31 on Jul 9, 2008 |
# ? Jul 9, 2008 22:27 |
|
Puddy1 posted:I'm new to django and python so go easy on me here, but what I'm trying to do is run some code whenever a model is saved to the database, although I don't know how to do that. Is there some sort of method I can overwrite when I save this particular model? http://www.djangoproject.com/documentation/model-api/#overriding-default-model-methods edit: BONUUUUUUUUUUS
|
# ? Jul 9, 2008 22:38 |
|
MonkeyMaker posted:OK, I can't figure this one out. I'm trying to provide an edit profile method for users to, well, edit their profiles. This includes image uploading. The following function works great for everything except that both their uploaded image and the renamed one get saved to the system. Obviously I only want the renamed one. code:
|
# ? Jul 9, 2008 23:42 |
|
duck monster posted:mod_python is loving terrible, unless you need to do a very small subscript of 'very wierd' apache tasks (such as rolling a http auth driver or something). Wait so there IS caching? drat no wonder. When I installed my app the other day on an actual server using mod_python the admin pages would randomly 404 on me. Like, completely randomly. The next day it was fine. If this is a sign of things to come maybe I should look into mod_fcgi.
|
# ? Jul 10, 2008 18:22 |
|
WickedMetalHead posted:webfaction seems to be decent for cheap hosting too. I've used webfaction for a few months, and for a shared host they are beyond awesome.
|
# ? Jul 11, 2008 00:26 |
|
Thanks Bonus and bitprophet for answering my previous question. I have another one for you guys now. I have this method in my view that gets called when I go to http://thesite.com/blah, but I'm only letting staff access it. The problem is I don't know how to login as staff to test this! I mean, I have the login information, I'm just a web development noob and have no clue how the request.user gets set to a staff member.
|
# ? Jul 11, 2008 03:35 |
|
if you have contrib.admin just login via your admin pannel?
|
# ? Jul 11, 2008 08:13 |
|
or if your asking how to restrict it, there is a shortcut for that, uh i forget waht it is though.
|
# ? Jul 11, 2008 08:15 |
|
It's late and I'm tired and I don't have the energy to go into detail (especially since this is one area I'm still learning a lot about) but look up context instances and what you have to do to access user information from a template. Also look up the decorators; when you include them you can put @login_required in front of a view function to restrict it to logged-in users. There are probably similar ones for staff and admins.
|
# ? Jul 11, 2008 11:17 |
|
WickedMetalHead posted:if you have contrib.admin just login via your admin pannel? Oh wow, I'm a moron, I was going to the wrong page, I got it working. Thanks.
|
# ? Jul 11, 2008 16:34 |
|
I'm getting a ViewDoesNotExist error, "Could not import problems.views. Error was: No module named views", when I try to get my app running on Dreamhost. I have views.py and models.py in the subdirectory "problems", and both of them work on my local machine. I've tried different chmod settings for the files. I also noticed that no .pyc files were being created. I tried doing python compileall.py, which created the .pyc but didn't affect the problem. I don't really understand what process normally compiles the .py files, so I'm not sure what else to do. Any ideas?
|
# ? Jul 17, 2008 02:48 |
|
Do most of you still use projects with Django? I was just reading http://www.pointy-stick.com/blog/2007/11/09/django-tip-developing-without-projects/ and it makes sense. I don't know what's considered best practices though...
|
# ? Jul 17, 2008 20:02 |
|
I typically use startproject. But keep all my apps on the python path. Then my apps are not tied to that particular project and are reusable.
|
# ? Jul 18, 2008 20:29 |
|
WickedMetalHead posted:I typically use startproject. But keep all my apps on the python path. Then my apps are not tied to that particular project and are reusable. Also, newforms-admin was merged to trunk 2 hours ago.
|
# ? Jul 19, 2008 03:24 |
|
saiyr posted:Also, newforms-admin was merged to trunk 2 hours ago. oh snap i didnt notice this! Time to play
|
# ? Jul 19, 2008 03:41 |
|
saiyr posted:Also, newforms-admin was merged to trunk 2 hours ago.
|
# ? Jul 19, 2008 04:49 |
|
Sivart13 posted:This is an epic change. Like, to the level that that trac page should have festive balloons and fireworks following your cursor. Followed by rewriting all your models.py files :\ It's a great change just breaks a lot.
|
# ? Jul 19, 2008 06:19 |
|
ATLbeer posted:Followed by rewriting all your models.py files :\ There's a snippet on djangosnippets that tries to automate creating the new admin.py files.
|
# ? Jul 19, 2008 08:27 |
|
Moving to NFA is not actually that hard, I've been using it for a while and had to rewrite my entire book's code examples to conform to it, a few months ago. Didn't take that long, considering. It's basically just replacing every inner Admin class with either a one-line "registration" of your model with the default admin site (if you did the "class Admin: pass" bit) or the one-line registration plus an external <Model class name>Admin class with whatever options you had in your inner class. The nice thing is that once you get used to this way of doing things you realize how much neater it is, and it's only one or two extra lines of code per model class, if that, depending on how many admin options you need. This plus the older newforms setup of having distinct ModelForm classes really refactors things so that your models, as chunks of code, are distinct from the forms and/or admin settings that relate to them.
|
# ? Jul 20, 2008 00:52 |
|
Is there any way to get ImageField to work on a Windows machine (for development, of course etc.)? It calls os.path.normpath internally, which causes forward slashes in upload_to to be converted into backward slashes. Needless to say, this doesn't work too well on a web server.
|
# ? Jul 21, 2008 19:13 |
|
That seems like an odd bug to me; what version are you using, 0.96 or some recentish SVN checkout? I would not be surprised if that was something extant in 0.96 that's been fixed more recently. If it's still around in SVN I'd say it was just overlooked, so look real hard for an existing Trac ticket about it (chances of one existing for something like this are high) and then add a note or patch to that ticket if none exists, or make a new ticket w/ patch if there isn't a ticket yet. Then, of course, feel free to patch your local version until that patch is accepted and merged to trunk
|
# ? Jul 21, 2008 20:32 |
|
Latest SVN version, but turns out I was somewhat jumping to conclusions, as it only affects the filename stored in the database and what's shown in the admin interface, not what the end result is. get_FOO_url() returns correct forward-slashed paths as expected
|
# ? Jul 21, 2008 22:24 |
|
I've been playing around with the alpha 1.0 release and newforms-admin and I've run into a roadblock. I've got three tables that I want to populate from one form. The tables are Volunteer, Address and Qualifications. Volunteer has a ForeignKey field for Addresses and a ManyToManyField for Qualifications. When I use newforms to generate a form for Volunteer, I get choice fields for both Address and Qualifications. The choice field for Qualifications is fine (and is populating fine) but I also get a choice field for Address, when I'd rather it render it's own input fields so users can enter new addresses. I can't find any way to get this to work. Is there documentation on this anywhere? Or any tips? All my attempts end at template exceptions or hard to track down errors. (I know I could build the form myself and handle the populating of seperate tables in the view, but I can't imagine what I'm trying to do isn't possible, I'm just not looking in the right place).
|
# ? Jul 27, 2008 22:10 |
|
What you want is called "inline editing" and in NFA it's handled with a few admin-related classes. See here for an example, I can't be arsed to find any official docs for it at the moment (not sure if/how any official docs for NFA were merged into the live site docs). So you just want to make an inline class for Address, and then mention it in an 'inlines' attribute of the admin class for Volunteer, and you should be all set. vvv Aha, that's where they stuck it, thanks. Will have to read it over to see how well it's improved over the old "docs" aka "a couple of infrequently updated wiki pages" bitprophet fucked around with this message at 13:33 on Jul 28, 2008 |
# ? Jul 28, 2008 00:52 |
|
Here's the inline stuff: http://www.djangoproject.com/documentation/admin/#inlinemodeladmin-objects
|
# ? Jul 28, 2008 03:05 |
|
Thanks for all the help I've gotten already (especially Bonus). I'd like to auto-populate the "user" field in a model (foreign key to User) with the current request.user when a ModelForm of this model is submitted. I've searched and found a couple of guides, but they're all from ye olde times before ModelForm. I don't really understand how to use the information in the docs, since I'm currently using generic views. Do I need to write my own form handling view for this, or is there an easy way to implement this using the update_object generic view?
|
# ? Jul 28, 2008 18:02 |
|
Hehe, no problem. If you have a ModelForm, you can pass a keyword argument of commit=false when you call its save method.code:
|
# ? Jul 28, 2008 18:17 |
|
I saw that in the docs, but I have no idea where to put that code or if it's possible to use this in conjunction with generic views.
|
# ? Jul 28, 2008 18:36 |
|
|
# ? May 16, 2024 11:48 |
|
In general, anything having to do with "code" implicitly means you can't use it with generic views, since generic views are what they are (namely a way to AVOID writing actual code). In order to use commit=False you'd need to write a wholly custom view for editing, which isn't that bad (it's maybe ten lines of code or so). It's usually an either-or decision like this; the only time you can mix generics with custom code is if your intended logic can fit around the generic view somehow (such as writing a view which sets up a QuerySet you can't built in a URLconf, and then calls the generic view with that QS, which does the rest of the work). The big thing about Django, then, is knowing what to use when; when to use the super shortcuts like generics or the admin, vs using the (still very rapid, thanks to the ORM and the forms library and so forth) approach of custom views. bitprophet fucked around with this message at 02:35 on Jul 29, 2008 |
# ? Jul 29, 2008 02:31 |