I'm trying to get Django setup on a Fedora Core box. I installed python, postgresql, mod_wsgi, and finally django. I added the following to my httpd.conf:code:
edit: I can ping the domain and it resolves to my server edit2: gently caress I don't know what the deal was but it finally started logging the error in error_log, it was a typo in my django.wsgi file, couldn't find my settings file Can I still use an htaccess file to password protect my dev environment? How would I do that? fletcher fucked around with this message at 01:48 on Jun 25, 2009 |
|
# ¿ Jun 25, 2009 01:08 |
|
|
# ¿ Apr 29, 2024 11:06 |
bitprophet posted:Since you've got access to the Apache config, just plunk whatever you would've put in a .htaccess file, into a <Location> block, e.g. Ahh, that's what I had tried originally. Forgot to put it in a Location block. Thanks!
|
|
# ¿ Jun 25, 2009 04:39 |
I'm a bit confused on how to organize my code into different apps, what portions deserve their own app, which ones to lump together, etc. Can somebody help me clarify this?
|
|
# ¿ Jun 25, 2009 22:52 |
I'm attempting to add the django-rest-framework SearchFilter with an existing Django project. settings.py: code:
code:
quote:FieldError at /api/employees/
|
|
# ¿ Aug 13, 2013 00:39 |
Finally got PyCharm setup so I could step through it. It didn't like search_fields being a str...I added a trailing comma to make it a tuple and now it works. Hooray!code:
|
|
# ¿ Aug 13, 2013 00:49 |
Any of you guys used django-pipeline before? I tried to follow these instructions but I can't seem to get it to work right. Installed the css & js compressor in my virtualenv: code:
code:
code:
code:
code:
code:
code:
|
|
# ¿ Aug 20, 2013 19:17 |
Bah! Finally figured it out! I needed to have the source_filenames start with myapp/ like this:code:
|
|
# ¿ Aug 20, 2013 23:22 |
I've got an ImageField that I want to use in Django REST Framework. How do I intercept the file upload so I can do things like rename the file or resize it and whatnot?
|
|
# ¿ Sep 6, 2013 23:54 |
Worked out great, thanks MonkeyMaker! Got another question now... My model has the following field: code:
quote:Warning: Field 'last_touched' doesn't have a default value Shouldn't auto_now_add take care of that for me? So I also tried: code:
fletcher fucked around with this message at 20:20 on Sep 12, 2013 |
|
# ¿ Sep 12, 2013 20:14 |
Yup I've been using South from the get-go, it is pretty sweet! Not sure what was up before with my auto_now, but it seems to be working now... Got another question now. Django REST Framework appears to respect the blank=True/False on my model definitions, which is great. Is it possible to make that dynamic though? Like, I want it to be blank=True if some_field='foo', but if some_field was set to 'bar' then I want blank=False. How should I go about doing that? I can sorta get there with custom permissions but then it just returns a 403 permission denied, rather than a 400 bad request with useful error messages.
|
|
# ¿ Sep 13, 2013 02:12 |
I've got an object that I need to access to all over the place, on every request. I've just been retrieving it as needed, but now when I look at my mysql query log I see the same query being executed 5 times within a single http request, obviously this is no good. I want it to be available like request.user is available, should I write a middleware component and stick this object on the request object?
|
|
# ¿ Sep 17, 2013 22:15 |
Ok cool, thanks for the advice! Got another one specific to Djangeo Rest Framework now that I'm looking at this query log. I added a SlugRelatedField to one of my serializers and the number of queries it's executing shot up quite a bit. I tried to add select_related() to my get_queryset method, and now it uses an INNER JOIN to get one of the relationships. This particular model has a ForeignKey to self though, and it doesn't seem to want to use an INNER JOIN to get to that one, it just executes a bunch of individual queries. Any ideas what might be causing that behavior?
|
|
# ¿ Sep 18, 2013 00:48 |
Is there any way to get access to the request object when overriding the model save() method? I was thinking I'd create a base model that has fields like modified_by, modified_datetime, etc and automatically populate them in the save() method of this base model, but I don't seem to have access to the request object to determine the value for modified_by (which is a ForeignKey to a Player object, not User, if that matters).
|
|
# ¿ Sep 18, 2013 23:32 |
I find myself creating nearly identical templates sometimes, one for Django and then one for Handlebars. Obviously this isn't ideal, since I have to maintain them in both places. I'm tempted to just use the Handlebars templates for all those cases, and simply render them in $(document).ready(). This has me wanting to be able to use my Django Rest Framework serializers in my Django templates, so the output of my Django template would just be a little placeholder element with a json object stuck in a data attribute or something, so it can be rendered using the Handlebars template client side. Is that possible? Is there some other way I should go about dealing with this?
|
|
# ¿ Sep 25, 2013 18:47 |
Anybody else have performance problems with the built in development server running inside a virtual machine? I've got Windows 7 for my host OS, Linux Mint 15 for my guest OS. When I hit a URL for my app using Firefox on Windows, it takes 20 seconds to load. Hitting the same URL with Firefox from inside the VM takes about 3 seconds to load. It is excruciating watching my CSS styles being applied rule by rule! Same crap performance using Chrome on the host OS. I suppose I could just use the browser in my VM all the time, but figured I might as well ask in case anybody else has run into this and knew how to fix it.
|
|
# ¿ Oct 15, 2013 22:38 |
Maluco Marinero posted:You might not have the correct virtualization flags set in your BIOS. They can make a huge difference to performance, and also allow you to run 64bit VMs. I would check that before troubleshooting other stuff. Went through and double checked all that stuff, seemed to look ok. Virtualization options enabled in the BIOS, IO APIC enabled, 4GB RAM allocated, 4 CPU cores, PAE/NX enabled, VT-x/AMD-V enabled, use host i/o cache, solid-state drive checked. Performance in the VM itself seems excellent, just the network performance from host to guest seems to suffer. I wonder if it's because I'm using NAT? As a test, I did a wget from the host OS to a 10MB file being served by runserver. Took a couple seconds to start and then transferred at 2MB/s.
|
|
# ¿ Oct 15, 2013 23:02 |
I'm trying to run ./manage.py test but I get:quote:DatabaseError: (1071, 'Specified key was too long; max key length is 767 bytes') I'm using MySQL, and the default charset is set to utf8mb4. From looking at the MySQL log, the test runner appears to be attempting to create the following table: code:
edit: oh and I tried setting TEST_CHARSET to latin1 in my settings.py, but that didn't seem to do anything? I don't want to use latin1 for my tests anyways but I thought that would allow me to temporarily get around this issue... fletcher fucked around with this message at 00:37 on Oct 16, 2013 |
|
# ¿ Oct 16, 2013 00:34 |
Of course I go weeks of putting up with that VM performance problem and it magically goes away hours after I decide to finally bitch about it. Seems nice and snappy now
|
|
# ¿ Oct 16, 2013 02:49 |
If I leave a field blank, I get a nice little This field is required. error message. If I put whitespace in there, it gets around the standard validation and does not throw that same error message. Some googling led me to this ticket where they concluded that is how the behavior will remain. I can't quite figure out how to implement that behavior myself though. I ended up with something like this: code:
|
|
# ¿ Oct 19, 2013 00:03 |
Thermopyle posted:I'm a little confused about what you're trying to do. Can you not use blank=True, null=True on the field? I have a field that is required, so I want blank=False, null=False. If you enter only whitespace as the value, it gets around the validation. So I just want to strip the whitespace from the value they enter, and if all they entered was whitespace, I want it to say "This field is required." without having to write the validation message myself.
|
|
# ¿ Oct 19, 2013 00:27 |
Pumpkin Pirate posted:The check for required fields being empty is done by the individual form fields. Form field cleaning is the first step of form cleaning, which happens before model cleaning, so by the time you're stripping the whitespace off, the check has already happened and succeeded. Thanks for the input guys. I suppose I'll go with the validator. It really seems like this should be the default behavior in Django though. I mean who would actually want to store whitespace as a value for a required field? Also, is there some convention for where the code for custom validators should live?
|
|
# ¿ Oct 21, 2013 19:35 |
Hmmm I'm not actually using any ModelForms, since all my froms post to Django REST Framework endpoints. That's why I was trying to do it at the model level.
|
|
# ¿ Oct 21, 2013 21:37 |
Anybody using AngularJS with your Django application? How's that working out?
|
|
# ¿ Oct 28, 2013 23:48 |
Is there a way to reconfigure a logging handler after it has been defined in settings.py? I want to override the filename of my FileHandler without touching settings.py.
|
|
# ¿ Oct 30, 2013 23:32 |
Thanks Thermopyle. For some reason nothing is being written to the log file in production (nginx + uwsgi), but it works fine in development with runserver. (this is without any dynamic handlers stuff) The file exists and is writable by the uwsgi user (0777). Didn't see anything unusual in the uwsgi log. Here's my logging settings: code:
code:
code:
fletcher fucked around with this message at 23:45 on Oct 31, 2013 |
|
# ¿ Oct 31, 2013 23:08 |
Well, it looks like it was actually working after all? I thought it wasn't working because I wasn't seeing sql queries being logged by django.db.backends.util. I added a log.debug() statement in urls.py and it made it into the log file. So now it's a question of why the sql queries are not being logged.
|
|
# ¿ Oct 31, 2013 23:59 |
Yay posted:Django's pretty quiet by default; you need to opt-in to most of the loggers that might be available, specficially 'django.db' in your case. But wouldn't my root logger for '' handle that? At any rate, I added 'django.db' but I'm still not getting any sql queries in the logs. code:
|
|
# ¿ Nov 1, 2013 19:34 |
NtotheTC posted:I do have the paid version, I didn't see the options for that though (admittedly I haven't looked thoroughly yet) Settings->Project Interpreters->Python Interpreters Click the green plus button on the right side and you can add a remote interpreter
|
|
# ¿ Nov 4, 2013 23:35 |
What's the workflow/environment setup if there's a Django package that I want to contribute to? I forked the repo, cloned it down, created a virtualenv, created a little demo app. At first I just did a pip install ./local/path/to/fork but that doesn't seem like the easiest way to start making changes to the library. I'm not supposed to make changes in site-packages and then merge them back into ./local/path/to/fork right? Am I suppose to use ./local/path/to/fork as my project root, and create my demo app inside there?
|
|
# ¿ Nov 6, 2013 21:26 |
MonkeyMaker posted:What's wrong with pip installing the local package, like you did? You might have to re-run your server or re-install your package sometimes, but it should work just fine. That's how I normally do it. Oh ok, I'll give that a shot then
|
|
# ¿ Nov 6, 2013 22:49 |
Baby Nanny posted:Use pip install -e. This will install the package in editable mode at the location of the code and will let you use it normally while still being able to code on it without having to re-run setup tools a bunch. Perfect!! Thank you.
|
|
# ¿ Nov 7, 2013 19:48 |
I still can't find out why queries are not being logged when I crank up the logging level...anybody have any other ideas?? Here's my last post about it.
|
|
# ¿ Nov 7, 2013 23:01 |
Pollyanna posted:So if I were to set up a simple one-page website that was more or less a set of posts (a database), a basic HTML template, a style sheet, and a .js for opening and collapsing posts or whatever, does that count as an app or is that something completely different? If it's not an app, what about it would have to change to make it count as one? Sounds like an app to me. In addition to what Baby Nanny mentioned, check out Projects vs. Apps on this page. Maybe your project is pollyanas_site and your only app is blog_app, which consists of exactly what you described. pollyanas_site has your settings.py, because that has stuff that is specific to you, like your email address or your database credentials. blog_app on the other hand, is more generic. If somebody also wanted blog_app, you could package it up, publish it, and tell them to pip install Django and then pip install blog_app.
|
|
# ¿ Nov 8, 2013 08:17 |
Pollyanna posted:Okay, I'm actually having some trouble now. I first tried Zinnia, but I ran into an issue where one of the modules it expected Django to have didn't exist (), so I tried to update Django. (I'm running in a venv now, so no worries) pip told me to upgrade it but then Django bitched about there already being an install, and told me to delete the sitepackages/django directory. I did that then tried to reinstall, but I can't because pip and easy_install say it's already installed. 1.6 is hot off the presses, you may want to stick with 1.5.5 for now until the libraries have a chance to catch up. I've never had to manually delete anything from sitepackaegs, not sure what happened there. What module was it complaining about Django missing? Copy/pasta the exact errors in here, somebody will be able to help you out. It sounds like maybe Django is installed outside of your virtualenv? Run deactivate to get out of your venv, then you should be able to do pip uninstall django to get rid of it. Otherwise you can tell venv to ignore those packages when you create your venv by using --no-site-packages. You don't even have to install Django in your venv before installing mezzanine, since mezzanine lists all the dependencies it needs, pip will automatically install the right versions of them: code:
|
|
# ¿ Nov 8, 2013 20:28 |
For those of you that use virtualenv-burrito, is there any reason I wouldn't want to source /home/fletcher/.venvburrito/startup.sh automatically when a shell is opened? Is ~/.bashrc the right place for that kind of thing?
|
|
# ¿ Nov 23, 2013 03:55 |
What are some good libraries to look at for caching models and querysets? django-cache-machine looks pretty nice. Or should I just use the low level caching API built into Django and just cache a few specific things here and there?
|
|
# ¿ Nov 26, 2013 20:37 |
It's safe to leave django-debug-toolbar in INSTALLED_APPS and MIDDLEWARE_CLASSES on production right? I know it's not supposed to do anything when DEBUG = False but I just wanted to double check.
|
|
# ¿ Nov 26, 2013 23:47 |
I'm playing around with django-mptt and I want cheap access to len(node.get_children()) so I don't have execute N queries to get the children count of N nodes. Any suggestions for how to go about this? I was thinking I might have to just add a children_count field on the model and calculate it in a cron job that runs in the background. I don't need this value to always be up to date, it's fine if there is a bit of a delay on it. I started going down the route of trying to cache the serialized response data to at least reduce the frequency that those N queries get executed, but it started to feel not quite right. edit: Nevermind, I just shoved it in memcached and called it a day. Don't want to spend forever trying to optimize this just yet. fletcher fucked around with this message at 23:48 on Dec 5, 2013 |
|
# ¿ Dec 5, 2013 03:35 |
I think something like this might also work. Basically since you want each MoodLog to be able to have multiple Feeling & Rating combos associated with it, those could be their own model, with a key that points back to the MoodLog they are associated with. Django then makes it easy to query the relationships between these tables.Python code:
code:
code:
code:
code:
|
|
# ¿ Dec 6, 2013 03:06 |
|
|
# ¿ Apr 29, 2024 11:06 |
edit: hah you beat me Pollyanna posted:Syncing the DB gives me this error, though: Since you have multiple foreign keys to Thought, Django is getting confused when it tries to create that *_set accessor, because they all end up with the same default name. Fortunately Django lets you specify a name, so they don't clash. Simplest way is to fix it is to tell Django not to create those *_set accessors, but doing: Python code:
Python code:
Python code:
code:
|
|
# ¿ Dec 6, 2013 05:04 |