|
fletcher posted:Anybody using AngularJS with your Django application? How's that working out? I've been migrating a more traditional Django application over to Django + AngularJS. Works fine. Basically don't use Django templating at all. Just use REST Framework along with Angular's $http or $resource and pretty much ditch using using traditional Django views.
|
# ? Oct 29, 2013 00:54 |
|
|
# ? May 15, 2024 06:39 |
|
I mentioned earlier that I had a script that I wanted to eventually load onto Django. It's basically a main logic .py with a folder containing a .pyc of all the functions used in it. It has some dependencies (Numpy, TA-lib, Matplotlib) that are installed on my computer, but I'm not sure if I can get them onto Heroku. What's the usual way to link a basic Python app to a Django project? Or is that not advisable?
|
# ? Oct 29, 2013 01:01 |
|
Pollyanna posted:I mentioned earlier that I had a script that I wanted to eventually load onto Django. It's basically a main logic .py with a folder containing a .pyc of all the functions used in it. This doesn't make much sense. Pollyanna posted:It has some dependencies (Numpy, TA-lib, Matplotlib) that are installed on my computer, but I'm not sure if I can get them onto Heroku. Dependencies are easy on Heroku if you have a requirements.txt. It just installs/compiles all the packages listed there. Pollyanna posted:What's the usual way to link a basic Python app to a Django project? Or is that not advisable? You just import what you need where you need it. If the file you run to run your standalone python application calls the function the_main_function() in __main__, then if you want to use that in (say) models.py, you just do from your_other_python_thingy import the_main_function at the top of models.py and then use it wherever you want.
|
# ? Oct 29, 2013 01:16 |
|
Umm, sure, but I don't quite get how my script would translate to HTML. Right now it's console based, where you type "a " and it gives you a thing. Would that basically just be replaced with a radio button or something if I move it over? Here's the script itself: http://pastebin.com/Q531b01t And yeah, I dunno what the deal with the functions module is. I forget why I did that. I changed it back and in the process found some pretty hilarious lines: Python code:
|
# ? Oct 29, 2013 01:54 |
|
Pollyanna posted:Umm, sure, but I don't quite get how my script would translate to HTML. Right now it's console based, where you type "a " and it gives you a thing. Would that basically just be replaced with a radio button or something if I move it over? Set up a form to get user input. Pass said data to your functions. Render a view with the results of your functions.
|
# ? Oct 29, 2013 01:58 |
|
Thermopyle posted:I've been migrating a more traditional Django application over to Django + AngularJS. Yeah, same experience. I've also got a traditional site with a single page that's angular driven, just use the verbatim tag and you're good to go.
|
# ? Oct 29, 2013 02:11 |
|
Thermopyle posted:Set up a form to get user input. I have a question: does the SQL database come into the picture here at all? Or is this something that doesn't really need to use it? It kinda seems like the latter because I'm not storing any data on the webpage, it's just generated on-the-fly.
|
# ? Oct 29, 2013 03:08 |
|
Pollyanna posted:I have a question: does the SQL database come into the picture here at all? Or is this something that doesn't really need to use it? It kinda seems like the latter because I'm not storing any data on the webpage, it's just generated on-the-fly. If you're not storing any data than you don't use the database. I question the use of Django at all if you don't need to store any data.
|
# ? Oct 29, 2013 03:12 |
|
Thermopyle posted:If you're not storing any data than you don't use the database. Er...I suppose you have a point. I imagined being able to output the results of the script to a webpage, but it's more easily done offline. vv I'll think of another approach.
|
# ? Oct 29, 2013 03:21 |
|
Pollyanna posted:Er...I suppose you have a point. I imagined being able to output the results of the script to a webpage, but it's more easily done offline. vv I'll think of another approach. No, I'm not saying a webpage won't work, I'm saying Django may not be the framework to use as a large part of the point of Django is how it works with a database.
|
# ? Oct 29, 2013 03:46 |
|
Pollyanna posted:Er...I suppose you have a point. I imagined being able to output the results of the script to a webpage, but it's more easily done offline. vv I'll think of another approach. Django thread OP 2.0 addresses this question but I am still drafting it up. You may want to look at something like http://flask.pocoo.org/ That said, you may want to just do this in Django to help you get a handle on how the framework operates at a basic level if you plan on doing work with databases at some point in python on the web.
|
# ? Oct 29, 2013 03:53 |
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 |
|
fletcher posted: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. Just get your logger and then remove the FileHandler from it and add a new FileHandler. Something like: Python code:
|
# ? Oct 31, 2013 00:07 |
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 |
|
fletcher posted:So now it's a question of why the sql queries are not being logged.
|
# ? Nov 1, 2013 08:29 |
|
The March Hare posted:OK, took some initiative to write part of this out. I'm not a Django pro (faaar from it) but I think I'm decent enough at making posts & I want/need feedback and additional info for this thing so here goes~. I'll throw some points into the suggestion box: links: DjangoPackages.com (well designed django package info/ranking site), ccbv.co.uk (Classy Class Based Views, an exceptionally put together reference), and DjangoCon US 2013 videos for the masochists among us. useful packages: Django-Rest-Framework may belong on the useful packages list, I think it'll be the next south (as in a package everyone uses, then three version later django-core implements it as the standard). It strives to remake the forms/views system inherent in django for backends, so you end up with serializers/api endpoints behaving just like you'd expect forms/views to. Podcast: Lincoln Loop does a great Podcast on Django. And for some reason the django blog post de jour is explaining how to use class based views, of which you can find a million on google. If you're interested in reading what the trending topics in django are, I recommend subscribing to the modestly popular http://www.reddit.com/r/django. Oh, in general suggestions, I feel like the most frequently asked question is (rightly) "Where do I start?", and the answer is almost always, resoundingly, "If you have a vague grasp of python, head over to the docs and complete the tutorial", which I think would make a great question 1 on the FAQ, as the tutorial can bring someone from zero to web developer who can work with the bigger concepts discussed elsewhere in the OP. Pythagoras a trois fucked around with this message at 18:15 on Nov 1, 2013 |
# ? Nov 1, 2013 15:50 |
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 |
|
At my new job to try and make it easier to setup the many libraries they use they provided a virtualbox on my machine running nginx/gunicorn that uses mounted folders from my dev box, so I modify code locally and then restart the service on the virtualbox so that it picks up the changes. The issue is I like to use Pycharm for Django work, and I'm not sure if it's possible to point my local pycharm copy to the virtual environment/settings.py/manage.py on the virtualbox. Is this a common setup, and is there a way to get pycharm to play nice with it?
|
# ? Nov 4, 2013 21:05 |
|
NtotheTC posted:At my new job to try and make it easier to setup the many libraries they use they provided a virtualbox on my machine running nginx/gunicorn that uses mounted folders from my dev box, so I modify code locally and then restart the service on the virtualbox so that it picks up the changes. The issue is I like to use Pycharm for Django work, and I'm not sure if it's possible to point my local pycharm copy to the virtual environment/settings.py/manage.py on the virtualbox. Is this a common setup, and is there a way to get pycharm to play nice with it? It looks like you need the paid version of pycharm to have its integrated tools run django on a remote system (the VM)
|
# ? Nov 4, 2013 21:14 |
|
I do have the paid version, I didn't see the options for that though (admittedly I haven't looked thoroughly yet)
|
# ? Nov 4, 2013 23:22 |
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 |
|
I am slowly descending into madness as I try to do stuff with Django ReST Framework and angular. Is there a good guide to making a completely decoupled django api and dumb MV* framework consumer because this is turning into yet another yak shaving black hole.
|
# ? Nov 6, 2013 02:25 |
|
Tavistock posted:I am slowly descending into madness as I try to do stuff with Django ReST Framework and angular. Is there a good guide to making a completely decoupled django api and dumb MV* framework consumer because this is turning into yet another yak shaving black hole. What in particular are you having issues with? There isn't much (to my knowledge at least) in the way of a general purpose guide for this. I've gone down the route of completely separating API/server (which is mostly Django and using REST framework) from a fat AngularJS client (separate projects, no mixed deployment, etc.), but most of the immediate "how am I going to do this now that I'm completely decoupled" things I had to work through myself. I know Thermopyle mentioned he was doing something similar, so maybe he has some insight here. If you can give specifics then I could make suggestions based on my experience.
|
# ? Nov 6, 2013 05:18 |
|
entr0py posted:What in particular are you having issues with? There isn't much (to my knowledge at least) in the way of a general purpose guide for this. I've gone down the route of completely separating API/server (which is mostly Django and using REST framework) from a fat AngularJS client (separate projects, no mixed deployment, etc.), but most of the immediate "how am I going to do this now that I'm completely decoupled" things I had to work through myself. I know Thermopyle mentioned he was doing something similar, so maybe he has some insight here. If you can give specifics then I could make suggestions based on my experience. It's a thousand cuts sort of deal where i keep fixing one problem and introducing another problem but I seem to be working through it fine. Is the project your talking about up on github or do you know any thin server/fat app projects I can look at that are built in django and angular because I'm interested in how things like CORs Headers are set up in production environments. Another thing I am having troubles with is user authentication and other 'contexts' but I'm sure that there is an easy way to do it, I just haven't figured it out. All this said I'm thinking about getting all this stuff figured out then writing something about it.
|
# ? Nov 6, 2013 05:40 |
|
Tavistock posted:It's a thousand cuts sort of deal where i keep fixing one problem and introducing another problem but I seem to be working through it fine. Is the project your talking about up on github or do you know any thin server/fat app projects I can look at that are built in django and angular because I'm interested in how things like CORs Headers are set up in production environments. Another thing I am having troubles with is user authentication and other 'contexts' but I'm sure that there is an easy way to do it, I just haven't figured it out. The projects are closed source, unfortunately, sorry. As far as example projects, I found that when I was just starting with a fat Angular app that reading just about any code that interacts with a backend API helped. I would look through ng-newsletter's articles and the Google+ group for anything that might sound applicable and see if it's worth studying the code. Here's some implementation recommendations based on what you mentioned though: CORS I'm assuming that the reason you're needing CORS handling is because your API is going to be on a different subdomain, or perhaps you have some sort of multi-tenant application where you have multiple sites on different domains accessing the API. In any event, you can try and simply leverage the existing CORS middleware, or write your own - it's relatively simple. If you wanted to do something that didn't require putting a domain in your settings file(s), you could write middleware that pulled from the Django sites framework for whitelisting, or perhaps pass in a header from nginx or your WSGI server for the site being served up. I don't think there's a wrong way to do it as long as you hit the primary security tenets of implementing CORS exceptions. Authn I'd recommend using token-based authentication and passing the authentication token as a header from $http or whatever request service you're using from your client (you can set default headers easily within Angular for $http). DRF should get you started with generating tokens and authenticating on them. You could still use session cookies if your site(s) and API are served from the same domain, but if you have any interest at all in accessing your API in other contexts (eg: not from a web browser), then just use token auth. Persisting the token client-side (localstorage or cookies) and expiring tokens is all simple enough and there should be literature out there for that if you need it. Authz Now, for authorization you can really do whatever fits your needs best. You can (and should, in my opinion) still rely on Django permissions for your API views. For most projects, introspecting permissions client-side to change application behavior is pretty common, so you will likely need to implement a service that handles this. You could pull down the user's permissions with a custom API view (or return it in a successful login response body) and write an Angular service with an API that mimics the simplistic one available in standard Django template contexts. You could also completely decouple Django permissions from your client-side behavior and instead build out a role-based authorization service in Angular and come up with a scheme for managing it on the API side. Hopefully that helps. I unfortunately work alone so I really only have previous co-workers in IRC to bounce things off of occasionally, so take my advice with a grain of salt and do as much of your own research as possible. entr0py fucked around with this message at 07:54 on Nov 6, 2013 |
# ? Nov 6, 2013 07:51 |
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 |
|
fletcher posted:What's the workflow/environment setup if there's a Django package that I want to contribute to? 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.
|
# ? Nov 6, 2013 21:36 |
|
I'm a beginner to web development; I've done the polls tutorial, and most of Tango with Django. I'm trying a simple project, and am struggling to apply what I've learned. I'm trying to automate a dull task at work using a webapp, since I can't install programs on work computers. I have a simple Python script that takes a block of text (I've set it up to accept files, or lists of strings, ie each line is an item), regexes latlong coords out of it, change their format and output a skyvector.com get URL. So, takes multi-line text as an input, outputs a string. I've set up a basic Django framework using Tango With Django as a template, but can't figure out how to 1: Get the input text field to show up and 2: accept that input, run it through my script, and display the output. For now, just displaying it as text will work. Relevant bits - views.py Python code:
Python code:
HTML code:
Dominoes fucked around with this message at 22:54 on Nov 6, 2013 |
# ? Nov 6, 2013 22:21 |
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 |
|
Dominoes posted:views.py You don't need a model, you just need to actually load the form in the view, at the moment you aren't doing that. Have a read, haven't done everything inside form.is_valid, but this should be a start for you. It should now render in the template. Python code:
Maluco Marinero fucked around with this message at 00:05 on Nov 7, 2013 |
# ? Nov 7, 2013 00:02 |
|
fletcher posted:What's the workflow/environment setup if there's a Django package that I want to contribute to? 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.
|
# ? Nov 7, 2013 15:21 |
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 |
|
This is kind of a dumb question, but what exactly does Django mean by an "app"? It can't just be a collection of webpages or like everything under a /whatever directory. What's the definition for it?
|
# ? Nov 8, 2013 04:51 |
|
Pollyanna posted:This is kind of a dumb question, but what exactly does Django mean by an "app"? It can't just be a collection of webpages or like everything under a /whatever directory. What's the definition for it? The first result for my google search of "what defines a django app" turned up a stackoverflow post (http://stackoverflow.com/questions/6301801/what-is-a-django-app-supposed-to-mean) which answered the question rather well: That SO Post posted:A Django app is a group of related functionality used to complete or maintain one aspect of a site.
|
# ? Nov 8, 2013 05:00 |
|
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?
|
# ? Nov 8, 2013 05:09 |
|
Pollyanna posted:This is kind of a dumb question, but what exactly does Django mean by an "app"? It can't just be a collection of webpages or like everything under a /whatever directory. What's the definition for it? Django projects are composed of multiple apps that contain specific project logic for a specific task of the website. They are also optional and you can just put all your code into one application and call it a day. You don't usually do this though because its easier to keep track of what does what if you move your code into decently organized apps. For example if you were making a blog you'd have an application that takes care of profiles, an app that could take care of posting, an app that could take care of managing file uploads, etc, etc. Your site / project is the culmination of all these apps. Having a well defined app structure is nice too because you can easily package apps into their own thing and use them in multiple projects quite easily. https://www.djangopackages.com/ for some good examples of that.
|
# ? Nov 8, 2013 05:11 |
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 |
|
|
# ? May 15, 2024 06:39 |
|
Hmmm...so what I could do is use someone else's blogging app, and design the website look myself, and it'll work? Cool. I do want to be able to put an app together at some point, but I think that'll depend on what I want to do. For now, this will work Thanks!
|
# ? Nov 8, 2013 16:32 |