|
Suspicious Dish posted:This has already been solved. Look up "input prediction" and "lag compensation". Yes, this is what I'm trying to do. How can I do it here without having forcing the need for two different sets of code?
|
# ? Apr 20, 2012 19:44 |
|
|
# ? Jun 8, 2024 09:39 |
|
German Joey posted:Yes, this is what I'm trying to do. How can I do it here without having forcing the need for two different sets of code? Both lag compensation and input prediction require different code on both the client and server. You don't have to have two different sets of code, you just have the client part in JavaScript, and the server part in Python.
|
# ? Apr 20, 2012 19:52 |
|
Maluco Marinero posted:AJAX Events are still restful so itll work just like a normal view. The question is how you want to handle non logged in users, because if you don't want to redirect but want something returned to the page, you'll probably be better off with your own decorator or mixin. code:
code:
|
# ? Apr 20, 2012 20:09 |
|
Suspicious Dish posted:Both lag compensation and input prediction require different code on both the client and server. You don't have to have two different sets of code, you just have the client part in JavaScript, and the server part in Python. Yes, again, NO loving poo poo. Hence the original post asking how I can link Python and Javascript, because I know both Python and Javascript are needed. However, although both are needed, I still do not want there to be two different sets of code describing "this is the formula for evading an attack" or "this is what how the monster decides what spell to cast this turn" so that when the designer decides that behaivor needs to change, it doesn't cause everything to get hosed up. Even if the end-result being that two different sets of code are needed, I'd still like the user to only need to write one set with the other set being "handled" somehow by the engine.
|
# ? Apr 20, 2012 20:13 |
|
ufarn posted:This doesn't currently work. What am I screwing up? You're probably forgetting about the CSRF protection. Use something like the jQuery cookie extension and: code:
|
# ? Apr 20, 2012 20:16 |
|
German Joey posted:Yes, again, NO loving poo poo. Woah, sorry. I misread your original post and response. Anyway, first of all, I'm not sure that Django is a good fit for a real-time thing like this. Something that can integrate with WebSockets for real-time server to client communication (rather than long-polling via AJAX) might be better. For something written in Python, you can try Twisted + WebSockets, but you'll still have the same issue of the Python/JavaScript disconnect. If your goal is "server and client parts are both written in JavaScript", have you considered using node.js or another JS server? EDIT: I don't think multi-language embedding is ever a good idea like this. If you want to concoct a solution where you fork out to SpiderMonkey and communicate over an fd with JSON (which is what Python-SpiderMonkey does, effectively), go ahead. pyjamas is a false start. PyPy used to have a javascript backend, but it has since been dropped because it's unmaintained. re: Python on the client, you could try using skulpt or emscripten, but ugh is that a terrible idea just use Python everywhere or JavaScript everywhere. Suspicious Dish fucked around with this message at 20:25 on Apr 20, 2012 |
# ? Apr 20, 2012 20:22 |
|
Suspicious Dish posted:You're probably forgetting about the CSRF protection. Use something like the jQuery cookie extension and: code:
|
# ? Apr 20, 2012 20:27 |
|
I'm having a problem making a custom filter. I've got an app 'pricetracker' installed in my settings.py, and I have a file 'project/pricetracker/templatetags/tag_extra.py', in a folder with an empty __init__.py, that contains : code:
code:
|
# ? Apr 22, 2012 17:44 |
|
It should be be available when you import pricetracker.templatetags.tag_extra.fadd and then try to use fadd. If you want to use it in your template you should need to put in a: {% load tag_extra %} Then use your tag
|
# ? Apr 22, 2012 18:31 |
|
Innocent Bystander posted:It should be be available when you import pricetracker.templatetags.tag_extra.fadd and then try to use fadd. If you want to use it in your template you should need to put in a: Turns out I actually had everything correct, it just wasn't loading until I restarted the Django server.
|
# ? Apr 22, 2012 19:11 |
|
I have kind of an unusual question. Part of the website I'm working on allows the admin to enter some custom HTML which will contain an HTML form. This raw HTML is then presented to the user. The user can fill out the form and hit submit, and then my code iterates over all returned values and stores them in the DB (I just build what is essentially a single line in a CSV file). The reason it's done this way is because the surveys the admin designs are much more complicated (in format) than any survey builder I've found is capable of building. She's very particular about how the survey looks. This site is a rewrite of an older site, and this is the way it's gotta be done until I can write a survey builder complex enough to satisfy her needs. Anyway, my question regards sanitization. I'm doing for key, values in sorted(request.POST.iterlists()): and building the CSV string using the key/values mappings. Do I need to worry about manually sanitizing key and values before storing them in the DB? Normally, I'd create a Form and just do form.cleaned_data, but that obviously doesn't work here. I can't find clear documentation telling me when the sanitization process occurs in Django, so I'm not sure if I can trust these data. If I can't trust them, what's the best way to sanitize them? Thanks! [edit] I just found this StackOverflow question which seems to tell me that Django's ORM will handle this. So I don't need to worry, right? Fangs404 fucked around with this message at 21:04 on May 2, 2012 |
# ? May 2, 2012 20:38 |
|
Have a look through this. When save is called, clean_fields is called, which runs the validator for each field. As far as I know that covers removing malicious input, but thatd be the methods to check. https://docs.djangoproject.com/en/dev/ref/models/instances edit: I'm a tool, seeing as I just learned about this when I was building a do / undo framework, and you're right. Save doesn't call model validation. Serves me right for answering a question hung over, sorry Maluco Marinero fucked around with this message at 06:28 on May 3, 2012 |
# ? May 3, 2012 03:18 |
|
Maluco Marinero posted:Have a look through this. When save is called, clean_fields is called, which runs the validator for each field. As far as I know that covers removing malicious input, but thatd be the methods to check. Not that I don't believe you, but I don't see anywhere in the docs where it says that save calls clean_fields. All I see is that save doesn't call full_clean. Is this what I should be doing?: code:
[edit] After digging around, it looks like the proper way to do this is by overriding the model's save method like this: code:
After actually playing around and trying "; DELETE * FROM surveys_surveyresponse; as a string response, it turns out that save does appear to sanitize the input correctly (it escapes the quote and turns it into ""). So I can just toss the raw POST data into the model, and save will make sure it's safe. Phew. Thanks! Fangs404 fucked around with this message at 05:53 on May 3, 2012 |
# ? May 3, 2012 05:11 |
|
Fangs404 posted:Not that I don't believe you, but I don't see anywhere in the docs where it says that save calls clean_fields. All I see is that save doesn't call full_clean. Is this what I should be doing?: Django's ORM properly prevents SQL injection. It does this using parameterized queries. What Model/Form Validation does is allow you to check for bad values and present a useful message to the end user. For example a models.URLField is just stored in the database as CharField, infact you can very well put things in an URLField that doesn't belong there by not calling clean (e.g. MyModel.url_field = "java script://alert('lol xss')"; MyModel.save(). if you had called full_clean on that it would throw a ValidationError since java script:// isn't an allowed value in the field. Essentially they are used for constraints that the database can't (without triggers or advanced types not available on all systems) support.
|
# ? May 4, 2012 00:35 |
|
Way to cancel Open Django East on me king_kilr! This sucks, trip cancelation will cost me moolah. (I know it's not his fault.)
|
# ? May 4, 2012 15:24 |
I have a Vote model in my application which I'd like to see applied to both tags and comments.code:
Jo fucked around with this message at 21:19 on May 7, 2012 |
|
# ? May 5, 2012 06:26 |
|
I'm pretty new to Python/Django in general, but I was able to get a basic blog rolled out without too much trouble. I think that so far what I like most is the templating language. Compared to Wordpress, it's a breeze to figure out and use and a lot of the built in filters are great too. Also that guide in the OP is horribly out of date. http://james-olson.com/ is the site I wrote, and launched on an AWS instance.
|
# ? May 8, 2012 20:21 |
|
Speaking of templating, does anyone else use hamlpy, the port of Ruby's haml. All it does is run a watcher than converts them to native django temples during development, but hamlpy is a really nice whitespace aware language. It makes my templates heaps more readable and you can always drop back to standard django inside the template.
|
# ? May 9, 2012 01:34 |
|
Jo posted:I have a Vote model in my application which I'd like to see applied to both tags and comments.
|
# ? May 9, 2012 03:46 |
|
Jo posted:I have a Vote model in my application which I'd like to see applied to both tags and comments. The dumb idea would be to use contenttype. Don't do that. I'd say that these deserve separate tables, rather than one table. Something like: code:
|
# ? May 9, 2012 03:55 |
|
You could also go the other way and make Tag and Comment both inherit a "Votable" base class, and have the vote just reference a Votable FK.
|
# ? May 9, 2012 14:56 |
SlightlyMadman posted:You could also go the other way and make Tag and Comment both inherit a "Votable" base class, and have the vote just reference a Votable FK. I kinda' like this solution. Will probably end up doing something like it. Thanks, everyone.
|
|
# ? May 11, 2012 00:47 |
|
Nimrod posted:
Oh, really? I was just about to go through it. Do people have recommendations for something similar that is up to date? I was planning to get started with django by making a really simple blog.
|
# ? May 14, 2012 14:45 |
|
SA's design doesn't lend itself very well to long-form code OPs, sadly. I don't think it looks all that obsolete, and upgrading to Django 1.4 doesn't require much except for changing your directory structure to moving the apps to the root folder instead of the project folder. Django By Example is a great series that should be in the OP.
|
# ? May 14, 2012 14:58 |
|
ufarn posted:Django By Example is a great series that should be in the OP. This looks perfect, thanks. What about http://www.djangobook.com/en/2.0/ ? Still worthwhile?
|
# ? May 14, 2012 15:13 |
|
fuf posted:This looks perfect, thanks. Include it with the warning that there is no guarantee that the code examples will work, and that they should make good use of the guide comments that fix most of these incompatibilities.
|
# ? May 14, 2012 15:19 |
|
ufarn posted:It will always be the best introduction to Django, woefully obsolete as it is. It's the tutorial Django deserves, but never really got, because it explains not just the Whats of Django, but also the Hows and Whys. It's a great argument against the criticism of Django as something clogged and clunky, when in fact it's the organic result of what people in publishing needed and developed. Yeah, the documentation is great for finding out implementation details, but Django Book really helped me align my thinking with how to use Django correctly.
|
# ? May 14, 2012 15:28 |
|
fuf posted:Oh, really? I was just about to go through it. Yeah, the OP does a few things, like: maxlength is now max_length To get any of your models to show in the admin panel, you now need to register them. __str__ is used throughout the OP instead of __unicode__, but to be fair it IS corrected near the top of the post, just not at any place after. The Django Docs/Django Book together were a better resources.
|
# ? May 14, 2012 15:58 |
|
Excuse me if this is out of place, but can some one explain to me or point me in the right direction with regards to running python with lighttpd? I gather I need wsgi? Or fast_cgi? Or huh? This is the closest thing I have found, and it does not help me one bit. http://redmine.lighttpd.net/projects/4/wiki/Howto_WSGI I have set up PHP, and that was pretty straight forward.
|
# ? May 15, 2012 15:55 |
|
Kaluza-Klein posted:Excuse me if this is out of place, but can some one explain to me or point me in the right direction with regards to running python with lighttpd? I gather I need wsgi? Or fast_cgi? Or huh? With Python you aren't inserting code into your HTML and letting the webserver execute it like with PHP. You generally use a Python web framework, something as complicated as Django to Pylons/Pyramid or to something very basic like Bottle. You then run that framework (or I guess your own app if you really want to do it yourself) with a WSGI server like gunicorn, paste, cherrypy or the like. You COULD just run that, but you should proxy to that with apache/lighttpd/nginx.
|
# ? May 15, 2012 20:28 |
|
You need to install python flup. Once you can import that, set up lighttpd to talk fastcgi on a specific port (not your external web port), then run manage.py in fastcgi mode to talk to the same port. I think the Django docs on this should get you there.
|
# ? May 15, 2012 22:10 |
|
Kaluza-Klein posted:Excuse me if this is out of place, but can some one explain to me or point me in the right direction with regards to running python with lighttpd? I gather I need wsgi? Or fast_cgi? Or huh? There's kind of a lot of stuff you have to wrap your head around with WSGI deployment, it is definitely not as straightforward as PHP. Here is a list of WSGI servers: http://www.wsgi.org/en/latest/servers.html I personally use apache mod_wsgi in production, but will be moving to uWSGI soon-ish. The basic idea is you have a front end web server (nginx in my case, but you can use apache or lighttpd) which knows how to pass through requests meant for the wsgi application to the proper wsgi server, which is running as some other process. You'll write a short wsgi script for your application (django 1.4 ships with an example wsgi script when you run `python manage.py startproject`), start up the wsgi server and pass it your wsgi script, and then configure the web server to pass through requests to the wsgi server. e: I recommend uWSGI over the other wsgi servers mentioned above. Looks like there is even a wiki page for using it with lighttpd specifically: http://projects.unbit.it/uwsgi/wiki/RunOnLighttpd (although it looks like you'd have to recompile lighttpd to use it, ugh. I also recommend moving to nginx if you can ) Lamacq fucked around with this message at 22:39 on May 15, 2012 |
# ? May 15, 2012 22:31 |
I have an application nearing completion, but I have no idea how hard it's going to hit memory, CPU, or the database. What are my options in terms of hosting it for a small group of people to test? Am I stuck with my local machine?
|
|
# ? May 17, 2012 20:23 |
|
Jo posted:I have an application nearing completion, but I have no idea how hard it's going to hit memory, CPU, or the database. What are my options in terms of hosting it for a small group of people to test? Am I stuck with my local machine? I just asked a pretty similar question in the hosting thread. I'm looking for some cheap shared hosting that has django support. http://www.webfaction.com/ looks like it could be good, but I'd like to get some other opinions.
|
# ? May 17, 2012 20:30 |
|
fuf posted:I just asked a pretty similar question in the hosting thread. I'm looking for some cheap shared hosting that has django support. I run a Django site on DreamHost and it works great. They have an entire section about it in their wiki, and simple step-by-step instructions: http://wiki.dreamhost.com/Django Here's a $50 off coupon code: SLIGHTLYMADMAN50 (disclaimer: I get a referral bonus too) http://www.dreamhost.com/r.cgi?265655
|
# ? May 17, 2012 21:13 |
I just want to be sure my IO operations are reasonable before I dump it on Dreamhost or someone. I have the niggling fear that one of my operations is going to completely obliterate the CPU and disk when more than ten or twenty people use it. (Yay perceptual image hashing.) I don't want to end up with a bill for $500 worth of memory/bandwidth/diskio overage, but I suppose if they'll just shut off service, that might be better. Side note: what is the most accepted way to do fuzzy string matching on the DB side? Right now I'm using a hack that looks like this: code:
EDIT: Table breakage.
|
|
# ? May 17, 2012 21:29 |
|
Just put it up on an amazon ec2 server, they charge flat rates on stuff like disk* and cpu usage. * Only on their local storage, if you use the EBS storage then those have usage charges $0.10 per 1 million I/O requests. I payed 16 bucks last month and I have thousands of users downloading videos off of EBS volumes.
|
# ? May 17, 2012 21:39 |
|
MEAT TREAT posted:Just put it up on an amazon ec2 server, they charge flat rates on stuff like disk* and cpu usage. Amazon is definitely the way to go if you can spend a couple bucks more and don't mind being your own sysadmin. I've got a few sites up there and it works great, just make sure you back poo poo up yourself, because they do have occasional server failures and don't perform any sort of backups themselves.
|
# ? May 17, 2012 22:28 |
|
SlightlyMadman posted:Amazon is definitely the way to go if you can spend a couple bucks more and don't mind being your own sysadmin. I've got a few sites up there and it works great, just make sure you back poo poo up yourself, because they do have occasional server failures and don't perform any sort of backups themselves. Not only this, but AWS has free tiers for which you might qualify, if you ever launch the site you can probably hand off half the poo poo to AWS anyways: database to RDS, caching to ElastiCache, content delivery to cloudfront, etc. As a general note, CloudFront is a ridiculously good CDN for the price, specially the latest iteration that got launched a few days ago.
|
# ? May 17, 2012 22:48 |
|
|
# ? Jun 8, 2024 09:39 |
|
deimos posted:Not only this, but AWS has free tiers for which you might qualify, if you ever launch the site you can probably hand off half the poo poo to AWS anyways: database to RDS, caching to ElastiCache, content delivery to cloudfront, etc. For some reason I've never managed to get a micro server to qualify for the free tier, but regardless a micro instance is about the same price as a shared hosting plan if your requirements aren't much it's not a bad deal. You can also resize it later if you need more. I have my Dreamhost account that runs my email, file server, and a dozen websites that don't get a ton of traffic, then an Amazon account where I launch anything that's "serious business."
|
# ? May 17, 2012 22:55 |