|
Tavistock posted:Is this a good way of making entries only visible to their owners? That's the way I do it, or well, I do: Python code:
NtotheTC fucked around with this message at 12:01 on Sep 16, 2013 |
# ? Sep 16, 2013 11:57 |
|
|
# ? May 16, 2024 17:59 |
|
You can always make a model manager that takes a user argument.code:
|
# ? Sep 16, 2013 16:51 |
|
I really like django-model-utils PassThroughManager.Python code:
Python code:
|
# ? Sep 16, 2013 18:26 |
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 |
|
fletcher posted: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? It'd make more sense to make it a context processor if you need it more in templates than in views. If you need it more in views, or equally in both, probably make a middleware.
|
# ? Sep 17, 2013 22:49 |
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 |
|
fletcher posted:Ok cool, thanks for the advice! IIRC, select_related() only works on forward-relationship FKs. Reverse-relationship FKs and ManyToManys require prefetch_related().
|
# ? Sep 18, 2013 17:04 |
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 |
|
fletcher posted: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). Only by passing it in. code:
code:
|
# ? Sep 18, 2013 23:46 |
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 |
|
I'm following the Getting Started With Django tutorial. I tried a few months ago, but gave up after vagrant/virtualbox/chef issues. I'm trying again, but can't forgot how to do the SSH step. Using Windows. I've run vagrant.up, converted my insecure_private-key to a .ppk using Puttygen, run Putty per the instructions, and logged in as "vagrant" in Putty's terminal. I think I need to cd to my gswd vagrant directory I ran vagrant up in, but I don't know how to do it, since now I'm cding from a fake Ubuntu putty box. Any ideas? Vagrant up in the main (non putty) terminal seemed to work, which is promising. On an experimental adventure: I tried typing vagrant ssh as the first command, and it prompted me to run sudo apt-get install vagrant. I did that, tried again, and was prompted to do vagrant init. Did that, tried again, and was told I have the wrong version of virtualbox and need 4.0 or 4.1. I'm not sure if it's referring to the version of vagrant I downloaded on my real computer, or the one apt-get installed. I tried uninstalling virtualbox and installing 4.1.26, but I get the same error. Do I need a specific version of 4.1? Overall, I'm just confused and am looking for instructions that leave nothing to the imagination. Is it possible to dive in to Django without this extra stuff? It's frustrating and unrewarding - opposite of Python. Dominoes fucked around with this message at 06:42 on Sep 30, 2013 |
# ? Sep 30, 2013 05:58 |
|
Dominoes posted:I'm following the Getting Started With Django tutorial. I tried a few months ago, but gave up after vagrant/virtualbox/chef issues. Try the official tutorial.
|
# ? Sep 30, 2013 06:40 |
|
Did it a few months back, but couldn't hurt to do it again. ATM I'm reading ahead in GSWD to see if it's possible to work through it without the extra software.
|
# ? Sep 30, 2013 06:41 |
|
What I ended up doing was ditching windows altogether (after getting fed up with all the strange byzantine workarounds I was doing) then not using vagrant at all to do Getting Started With Django. I was ramming my head against a wall trying to do all the stuff in windows when I noticed that everything I wanted to do seemed to be built for Linux/MacOS. The switch was super easy to Ubuntu and after a week I had everything filling comfortable. This isn't answering your question but I think it might be worth your time to try switching to a unix-like. To answer your question I did just fine not using Vagrant but with the caveat of "I was using Ubuntu". If you have any questions or need help setting up Ubuntu hit me up at {myusername}91@gmail.com
|
# ? Sep 30, 2013 06:52 |
|
Thanks dude - I think I'll take your advice and give it a shot on my Ubuntu laptop.
|
# ? Sep 30, 2013 07:09 |
|
As the creator of GSWD, yes, you can do it all without Vagrant and VirtualBox. I mostly provided the box so I wouldn't have to answer "how do I install Python, etc" on Windows.
|
# ? Sep 30, 2013 17:38 |
|
Is there an app for an interactive Python shell you can add to your website? I have an input string/file that I want to run a script on, and I want it to basically be a text box + converter similar to what this website does. Is there an option for this, or is there a better way to do it?
|
# ? Oct 10, 2013 16:36 |
|
Why do you need an entire interactive python shell embedded into your site to do a value conversion?
|
# ? Oct 10, 2013 16:49 |
|
Don't embed Python into the web. It's just not meant for secure execution. Just learn JavaScript.
|
# ? Oct 10, 2013 16:53 |
|
The script as it is right now takes raw input (name of local file). The strings can be very long, so I'd like to give it the option of translating directly from that. I can have a text box too, of course. In that case, do I just need to pass the string or filename into the script from the text box and have it output directly onto the webpage? Is there an object/model for accessing a Python script and returning the result? Suspicious Dish posted:Don't embed Python into the web. It's just not meant for secure execution. Just learn JavaScript. What does secure execution mean in this case? It's mostly for personal use, so I don't think anyone will try and access my computer.
|
# ? Oct 10, 2013 16:54 |
|
By "secure execution" I mean "if you give somebody a Python prompt, even if you try really hard to sandbox it, they will always find a way to break through". And execute arbitrary code on your computer, and cause it to delete files, and steal all your porn. Why, then, do you want it in a web page then, instead of just using Python on your local computer?
|
# ? Oct 10, 2013 17:01 |
|
Pollyanna posted:Is there an object/model for accessing a Python script and returning the result? Django is written in python, you can pass your input or file to django as a request and execute the script safely on the server-side, then return the output as a response.
|
# ? Oct 10, 2013 17:20 |
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 |
|
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.
|
# ? Oct 15, 2013 22:42 |
|
fletcher posted: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. I run an Ubuntu VM in a Vagrant on my Mac and don't have speed issues anywhere near that long. Maybe a few extra milliseconds.
|
# ? Oct 15, 2013 22:44 |
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 |
|
I'm trying to push Django onto Heroku. When I run git push heroku master, I get this error:code:
code:
EDIT: Never mind, blame Git. edit2: In fact, I'm gonna ask about deploying Django. I know that Heroku seems to be fairly popular, but I've found that deploying Django to it is kind of a pain. What's the best service to use? Pollyanna fucked around with this message at 21:11 on Oct 18, 2013 |
# ? Oct 18, 2013 16:47 |
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 |
|
Pollyanna posted:edit2: In fact, I'm gonna ask about deploying Django. I know that Heroku seems to be fairly popular, but I've found that deploying Django to it is kind of a pain. What's the best service to use? You're doing something wrong. Deploying Django to Heroku is super easy. fletcher posted: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. I'm a little confused about what you're trying to do. Can you not use blank=True, null=True on the field?
|
# ? Oct 19, 2013 00:14 |
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 |
|
Thermopyle posted:You're doing something wrong. Deploying Django to Heroku is super easy. That may be the case. I guess I'll try again once I get more familiar with Django. Speaking of, forgive me for asking yet more questions, but I'm kind of bewildered by something I want to do. After going through the demo on the Django site (the one about making polls), I've decided that I want a homepage to be displayed when you go to localhost:8000. However, I haven't written a webpage in over 13 years and the last time I did, it was hand-typed in HTML. The way Django structures itself, a single subdirectory ("app") contains files that somehow make a webpage/.html, and apparently it's a bad idea to put any models.py or views.py scripts in the root folder. Assuming that the /polls subdirectory is equivalent to localhost:8000/polls/, shouldn't I be able to put an HTML page at localhost:8000/ ? Django generally works by creating "apps" within a project, though, and I don't understand how an "app" would create a homepage. Maybe I'm just way out of date on my web development, but this doesn't make much sense to me.
|
# ? Oct 19, 2013 01:05 |
|
Pollyanna posted:That may be the case. I guess I'll try again once I get more familiar with Django. The url you visit has nothing to do with the filesystem path. When you visit an url like the root url, Django looks in urls.py to determine which view to render. You create a view in views.py. That view passes smashes data into a template that you can really put wherever you want, however there are conventions for template locations. If it's a template for an app, class-based views expect it in app/templates/app/. So, what you see when you visit localhost/ or localhost/butts or localhost/foo is determined by urls.py selecting a view out of views.py which selects a template out of wherever you configure the view to look. Hell, you can have all of the urls point to the same view.
|
# ? Oct 19, 2013 01:17 |
|
Goes to show that I have a lot more to learn. I have a new error: now I get "ImportError: No module named _collections". It was literally working just a second ago, but then I tried to runserver and now it's dying on me. edit: I can't even run help() in the Python shell. What the hell happened? Pollyanna fucked around with this message at 01:51 on Oct 19, 2013 |
# ? Oct 19, 2013 01:46 |
|
Pollyanna posted:Goes to show that I have a lot more to learn. What operating system are you working in? Also, I saw that you said you were using virtualenv, make sure that is working properly. You could be calling a different/nonexistant python installation.
|
# ? Oct 19, 2013 02:44 |
|
The March Hare posted:What operating system are you working in? Um, I'm on OSX. I actually decided to scrap the whole project and start again, which involved deleting the "venv" folder...I think that's what hosed me up. You said that it should be working properly/calling a nonexistent python installation, and I think that's what's happening maybe. How do I fix it? What's worse, here's what happens when I try to run virtualenv: code:
|
# ? Oct 19, 2013 02:49 |
|
Pollyanna posted:Um, I'm on OSX. I actually decided to scrap the whole project and start again, which involved deleting the "venv" folder...I think that's what hosed me up. You said that it should be working properly/calling a nonexistent python installation, and I think that's what's happening maybe. How do I fix it? Type 'which python' into the terminal. If you aren't in a virtualenv it should say something like /usr/bin/python on osx, that would mean that all of your python stuff is coming out of the default system-wide python installation on osx. I suspect your terminal session is still in the virtualenv that you have now deleted, and so it is trying to do all of these things using installations of python and easy_install and whatever else but cannot, because all of the files that do those things are missing because you deleted them. When you run source bin/activate like the virtualenv tutorial tells you to it changes where your system looks for python and such to that directory (which was created by virtualenv, and which contains isolated installs of python and other things), instead of the default system install. Try typing 'deactivate' and then doing whatever else, should turn off the virtualenv session if you are in one. (By turn off I mean it will reset your path to the system default, which you almost certainly have not deleted, which will then allow you to do things again.) The March Hare fucked around with this message at 03:03 on Oct 19, 2013 |
# ? Oct 19, 2013 03:01 |
|
code:
|
# ? Oct 19, 2013 03:07 |
|
|
# ? May 16, 2024 17:59 |
|
Pollyanna posted:
Erghhh, can you paste the response from echo $PATH because I have no idea what is going on.
|
# ? Oct 19, 2013 03:22 |