|
Maluco Marinero posted:Show me your current admin code and I'll see how I can help. models.py: Python code:
Python code:
|
# ? Dec 7, 2013 00:46 |
|
|
# ? May 16, 2024 17:58 |
|
I'd like to allow a user to add additional fields by pressing a button. I've set up a basic system for having multiple fields, and am already having trouble. I have a loop to add additional fields and store them in a list, but storing them in a list doesn’t add them to the form's visible fields attribute, which I'm looping over in the template. The fields are implicitly added when simply stored to a variable within the class, but I can't figure out how to do that with a loop. Stripped down code: Python code:
Python code:
Dominoes fucked around with this message at 14:21 on Dec 7, 2013 |
# ? Dec 7, 2013 14:18 |
|
I am going crazy trying to figure out how to get django set up with pip and virtualenv and all that jazz. The Tango with Django tutorial wants you to use pythonbrew and "switch" to Python 2.7.5. This works fine, but then when I use pip to install django it installs under the system version of python, not the pythonbrew version. So everything stops with "module django not found". So I figured I would forget pythonbrew and skip straight to using virtualenv and virtualenvwrapper, because they seem to be so popular. But it seems like virtualenv projects just use the system version of python? How do I get it to use Python 2.7.5? Basically I have two questions. The first is the most important, because it'll give me something to aim for: 1) How do pros deploy django on a production server? Assuming I want it running on my own server and not on pythonanywhere etc. Do people run actual deployed django apps in virtual environments? Or is that just a development thing? Do you use the system install of Python, or a separate one? (PyPy?) My other question is lazier, but any help appreciated: 2) What's the easiest way to install and use python 2.7.5 and django 1.5.4 on my development server?
|
# ? Dec 10, 2013 16:54 |
|
Skip the virtual environment stuff for now; you don't need it to do TWD. You don't need the specific version they run either.
|
# ? Dec 10, 2013 18:01 |
|
Alright cool, I'll just use the system python interpreter while I do the tutorial and hope for the best. But eventually I'll have to deal with the deployment question, and whether or not to use an isolated python interpreter, so I'd still be interested in hearing how other people do it.
|
# ? Dec 10, 2013 18:26 |
|
You can use specific python version with virtualenv with --python flag. Check the docs. My dev server is a PI and it works fine with virtualenv. Prod will depend on the server at your disposal.
|
# ? Dec 11, 2013 02:18 |
|
I've just started my very first Django project, which right now aims to be a character builder for a tabletop roleplaying system. One day maybe I'll figure out how to do input not through the admin panel, but I'm taking it very slow so I don't get overwhelmed. My current stumbling block is an issue of display. I've got the contents of my database displaying just fine in a simple website, but I'd like to have it display as a repeating series of characters rather than just the stored integer. My code right now is pretty simple, displaying like so in a table: HTML code:
|
# ? Dec 18, 2013 15:44 |
|
morcant posted:I've just started my very first Django project, which right now aims to be a character builder for a tabletop roleplaying system. One day maybe I'll figure out how to do input not through the admin panel, but I'm taking it very slow so I don't get overwhelmed. My current stumbling block is an issue of display. I've got the contents of my database displaying just fine in a simple website, but I'd like to have it display as a repeating series of characters rather than just the stored integer. Python code:
EDIT: I was horribly wrong... I just tested and that doesn't work. The "right" way would be to add a class to an element in the TD and have a tiling sprite image background. To do it your way you'll need to either create the strings and add them to the context, or make ranges and add them to the context, and then iterate over those ranges in the template. Lumpy fucked around with this message at 16:28 on Dec 18, 2013 |
# ? Dec 18, 2013 16:11 |
|
morcant posted:
So, this is possibly a bit beyond where you are but this is a great time to learn about custom template tags. You mention being able to do it in Python. Well, tags let you write custom python to use in your templates. Start off by creating a directory named `templatetags` in your app and create an `__init__.py` in there. Then create a file to hold your template tags and filters. Generally this is `<app_name>_tags.py` but you can call it whatever you want. I'll call it `character_tags.py` because I can. So, in `character_tags.py`, we'll do: code:
HTML code:
|
# ? Dec 18, 2013 18:56 |
|
It worked! Thank you very much! I'm not sure what decorators are as yet, but I'll do some research. I'll definitely figure it out for my second draft when I'll (hopefully) have stuff that responds to appropriate Attribute value - you can't be "Indomitable" without Resolve >= 3, etc.
|
# ? Dec 18, 2013 20:52 |
This logging thing is driving me mad. I don't even want to actually log SQL queries, I just want to know why it's not working. Added my logger: code:
code:
code:
When I hit my Django app through the webserver, however, nothing from django.db.backends gets written to the logs. If I change DEBUG=False to DEBUG=True in my settings, lots of stuff from django.db.backends gets written to the logs. I can't find anything that would suggest the logging is tied to that DEBUG setting though. edit: ughhhh how did I miss this: quote:For performance reasons, SQL logging is only enabled when settings.DEBUG is set to True, regardless of the logging level or handlers that are installed. fletcher fucked around with this message at 02:43 on Dec 19, 2013 |
|
# ? Dec 19, 2013 02:40 |
code:
|
|
# ? Dec 27, 2013 00:55 |
|
It's been a while since I last used Django, so has anyone used RedirectView on Django 1.6? I'm having some trouble getting the url reversal part to work, and Googling around isn't helping too much. Essentially, I want to be able to direct urls like mysite.com/100?image=44 to urls like mysite.com/100/100?image=44 while preserving the query string. I have a project with the app "mainapp". In my project-level urls.py, I have the following code: Python code:
Python code:
Python code:
The Github source code just uses the reverse method, and if I debug by adding the line Python code:
pre:u'mainapp' is not a registered namespace However, if I have the request_square url call the following view code instead, things work fine, so I'm completely lost why it wouldn't work as a RedirectView. Python code:
|
# ? Dec 28, 2013 19:13 |
|
Anyone know how to run South? I did 'from south.db import db', and was greeted with "ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings." I tried south.settings.configure() and django.settings.confgure(), but neither are valid commands.
|
# ? Jan 14, 2014 21:42 |
Dominoes posted:Anyone know how to run South? I did 'from south.db import db', and was greeted with "ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings." I've been using South but I've never had to manually write an import statement like that, all I ever do is: code:
Also, you can specify that environment variable at the top of your script (none of my migrations actually do this though): code:
|
|
# ? Jan 14, 2014 22:03 |
|
I was going off this Stack overflow thread I'm trying to rename a column. I don't understand why Databases (and therefore Django models) are so finicky about changing things, but apparently South is the solution. I want to run this: 'db.rename_column('app', 'old', 'new')', which requires importing db. I don't need to migrate anything, I just want to be able to change database columns without starting from scratch each time. Dominoes fucked around with this message at 22:17 on Jan 14, 2014 |
# ? Jan 14, 2014 22:15 |
Dominoes posted:I was going off this Stack overflow thread I see, you want a data migration then. First create an empty data migration: code:
Then run the migration: code:
|
|
# ? Jan 14, 2014 22:33 |
|
I have a (probably) simple question regarding querying in Django. Basically I have a time table and I want to query times around a certain value. For instance if I query for 15:00 I want it to show me the two nearest results that are higher and two that are lower than that time. I can't chain two slices together so I'm not sure how to limit results both higher and lower. Should I make two separate queries and then merge them together or is there a more elegant way?
|
# ? Jan 15, 2014 16:54 |
|
Thanks fletcher - got it sorted using the first two lines you linked, after adding south to my installed apps, and running convert_to_south.
|
# ? Jan 15, 2014 17:04 |
Cool! Glad you got it working. My turn for a question - Is there a better way I should be doing something like this? I want it to handle the case where last_id might not be specified, or if it is, making sure it's the right data type. code:
|
|
# ? Jan 16, 2014 04:29 |
|
I've got an Openshift/Django issue: I'm having difficulty getting stylesheets and my SQLite database working in Openshift. When attempting to access a page that uses the database, I get the following Django debug message: "no such table: mytable". I get the same in rhc tail. Everything else appears to work. My local file setup: code:
code:
Python code:
Dominoes fucked around with this message at 18:49 on Jan 16, 2014 |
# ? Jan 16, 2014 18:26 |
|
Is The Django Book a good book to start with? I read some of it and I really liked it, but I was told it's extremely outdated.
|
# ? Jan 18, 2014 15:02 |
|
Cowabanga posted:Is The Django Book a good book to start with? I read some of it and I really liked it, but I was told it's extremely outdated.
|
# ? Jan 18, 2014 15:56 |
|
ufarn posted:It is. It's a great explanation of why Django was designed the way it was, and truly the best programming/framework guide I've ever read, but I'd worry it teaches you something wrong or bad habits at this point. Do you suggest an alternative?
|
# ? Jan 18, 2014 17:47 |
|
Cowabanga posted:Do you suggest an alternative? I'd say try out the Django Book and find some example project to work on, and figure out what things you need to complete it.
|
# ? Jan 18, 2014 18:45 |
|
Newer guides are http://gettingstartedwithdjango.com/ and http://www.tangowithdjango.com/
|
# ? Jan 18, 2014 19:46 |
|
etcetera08 posted:Newer guides are http://gettingstartedwithdjango.com/ and http://www.tangowithdjango.com/ Yeah, I'm really paranoid I'm gonna have a hard time with a tutorial that's crazy outdated, so these should do. Thanks!
|
# ? Jan 19, 2014 11:39 |
|
Cowabanga posted:Yeah, I'm really paranoid I'm gonna have a hard time with a tutorial that's crazy outdated, so these should do. Thanks!
|
# ? Jan 19, 2014 12:02 |
|
Once you get past the basics, I recommend spending some time reading through applicable Django source code too. Some of it isn't the best Python but most of it is well-documented and tested and I learned more about what I was doing through that method than anything else. Of course, it won't make much sense until you get past the basics anyways.
|
# ? Jan 19, 2014 17:40 |
|
Another tip: While you'll be fine with the official Django tutorial and TWD, if you're reading a tutorial that involves multiple third-party tools that are not working and/or confusing you, run.
|
# ? Jan 19, 2014 17:43 |
|
Dominoes posted:Another tip: While you'll be fine with the official Django tutorial and TWD, if you're reading a tutorial that involves multiple third-party tools that are not working and/or confusing you, run. Honestly, the tutorial and the docs will get you plenty far on their own as well.
|
# ? Jan 21, 2014 15:51 |
|
I'm using aws for my django application, and I'm getting timeouts when uploading large files. Does anyone have an elegant solution for doing django uploads that don't timeout? I think the timeout is something to do with s3 not contacting the django app to say "there is still a connection, don't timeout for the user".
|
# ? Jan 26, 2014 01:02 |
|
Megaman posted:I'm using aws for my django application, and I'm getting timeouts when uploading large files. Does anyone have an elegant solution for doing django uploads that don't timeout? I think the timeout is something to do with s3 not contacting the django app to say "there is still a connection, don't timeout for the user".
|
# ? Jan 26, 2014 01:04 |
|
Dominoes posted:Shot in the dark: Are you using read() instead of chunk()? I'm using chunk
|
# ? Jan 26, 2014 18:46 |
|
So, potentially dumb question here but I've spent some time googling and have come up empty. I have an app that users log into, and when a user logs in I want to spawn a persistent socket connection to an external service and associate that connection with the user On a conceptual level, I basically want a stateful worker that I can use to drive events in my frontend via long polling or what have you. Can anyone point me in the right direction?
|
# ? Jan 28, 2014 11:25 |
|
Megaman posted:I'm using chunk Any ideas?
|
# ? Jan 28, 2014 22:37 |
Megaman posted:Any ideas? What are you using to transfer the files from your django app server to S3?
|
|
# ? Jan 28, 2014 22:42 |
|
fletcher posted:What are you using to transfer the files from your django app server to S3? Files are uploaded to the actual servers, then uploaded to s3. This seems like a step too many? Do people usually use forms to have users directly upload to s3 to get around using the servers? Then the issue is uuid/keys of said files.
|
# ? Jan 29, 2014 16:05 |
Megaman posted:Files are uploaded to the actual servers, then uploaded to s3. This seems like a step too many? Do people usually use forms to have users directly upload to s3 to get around using the servers? Then the issue is uuid/keys of said files. That sounds fine, your servers probably have to be the proxy to s3 to avoid cross domain security stuff. But what are you using to communicate with S3? If you eliminate the S3 step and just save them to your servers, does the upload still timeout?
|
|
# ? Jan 29, 2014 18:45 |
|
|
# ? May 16, 2024 17:58 |
|
fletcher posted:That sounds fine, your servers probably have to be the proxy to s3 to avoid cross domain security stuff. But what are you using to communicate with S3? If you eliminate the S3 step and just save them to your servers, does the upload still timeout? Nope, the timeout happens between the server and s3. We also can't store on the server, we have tons of data, thus s3. I was thinking the client could upload from our app directly to s3, wouldn't that be a valid solution to this? We could just cut out the server.
|
# ? Jan 29, 2014 19:47 |