Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

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.

Adbot
ADBOT LOVES YOU

Pollyanna
Mar 5, 2005

Milk's on them.


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?

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

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.

Pollyanna
Mar 5, 2005

Milk's on them.


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 :downs:" 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:
def ask_symbol():
    symbol = raw_input('Look up which symbol?\n>')
    print '\nFetching data for ' + symbol + '...' + '\n'
    return symbol

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

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 :downs:" 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:
def ask_symbol():
    symbol = raw_input('Look up which symbol?\n>')
    print '\nFetching data for ' + symbol + '...' + '\n'
    return symbol

Set up a form to get user input.
Pass said data to your functions.
Render a view with the results of your functions.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

Thermopyle posted:

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.

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.

Pollyanna
Mar 5, 2005

Milk's on them.


Thermopyle posted:

Set up a form to get user input.
Pass said data to your functions.
Render a view with the results of your functions.

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.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

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.

Pollyanna
Mar 5, 2005

Milk's on them.


Thermopyle posted:

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.

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. v:shobon:v I'll think of another approach.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

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. v:shobon:v 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.

The March Hare
Oct 15, 2006

Je rêve d'un
Wayne's World 3
Buglord

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. v:shobon:v 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.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
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.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

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:
logger = logging.getLogger(__name__)
The handlers are in logger.handlers. I don't remember how you identify the FileHandler off hand, but just iterate over it and inspect the objects in it and you'll figure it out. Then remove that or reconfigure it.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
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:
LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'verbose': {
            'format': '[%(asctime)s] %(levelname)s %(pathname)s:%(lineno)d %(message)s'
        }
    },
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'handlers': {
        'file': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'formatter': 'verbose',
            'filename': '/var/log/django/mysite.log'
        },
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        '': {
            'handlers': ['file'],
            'level': 'DEBUG'
        },
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}
edit: This seems to write to the log file just fine...why can't my app?
code:
$ source ./my-venv/bin/activate
(my-env) $ python manage.py shell
>>> import logging
>>> log = logging.getLogger('test')
>>> log.debug('hello world')
edit2: This script, however, writes nothing to the log?
code:
(my-env) $ cat /tmp/logtest.py
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

import logging

log = logging.getLogger('test')
log.debug('hello world')
(my-env) $ python /tmp/logtest.py

fletcher fucked around with this message at 23:45 on Oct 31, 2013

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
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.

Yay
Aug 4, 2007

fletcher posted:

So now it's a question of why the sql queries are not being logged.
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.

Pythagoras a trois
Feb 19, 2004

I have a lot of points to make and I will make them later.

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~.

https://docs.google.com/document/d/1jNYFVwEwAPBkk7X1calp28hZv5nlPEqQwPWUafmNcTw/edit?usp=sharing

Please correct me if I'm wrong and leave feedback on what to expand on in this thing. The organization is not set in stone, this is meant to be a really communal effort so if some of the more experienced Django devs in here can do some effortposting to flesh this thing out, that would be great.

Additionally, if you know of any good learning resources, or you are learning right now and you have feedback about any of the beginner links or anything, that advice is welcome and very helpful as well.

The doc is open for in-doc discussions via comments, but I'm going to do the editing just as a measure of moderation to keep this thing from getting out of hand. I think we should be OK to discuss changes in-thread too, but if it gets lengthy I have plat and can be contacted at marchharesa@gmail.com too.

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

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

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:
LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'verbose': {
            'format': '[%(asctime)s] %(levelname)s %(pathname)s:%(lineno)d %(message)s'
        }
    },
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'handlers': {
        'file': {
            'level': 'DEBUG',
            'class': 'logging.FileHandler',
            'formatter': 'verbose',
            'filename': '/var/log/django/mysite.log'
        },
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        '': {
            'handlers': ['file'],
            'level': 'DEBUG'
        },
        'django.db': {
            'handlers': ['file'],
            'level': 'DEBUG'
        }
    }
}

NtotheTC
Dec 31, 2007


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?

mewse
May 2, 2006

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)

NtotheTC
Dec 31, 2007


I do have the paid version, I didn't see the options for that though (admittedly I haven't looked thoroughly yet)

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

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

Tavistock
Oct 30, 2010



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.:nsa:

entr0py
Jan 31, 2004


A real-life robot.

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.:nsa:

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.

Tavistock
Oct 30, 2010



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.

entr0py
Jan 31, 2004


A real-life robot.

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.

All this said I'm thinking about getting all this stuff figured out then writing something about it.

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

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
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?

MonkeyMaker
May 22, 2006

What's your poison, sir?

fletcher posted:

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?

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.

Dominoes
Sep 20, 2007

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:
from django.shortcuts import render_to_response
from django.template import RequestContext

from royals import mycode

def index(request):
    context = RequestContext(request)
    
    if request.method == 'POST':
        royal_text = royal_form_entry.Text()
        skyv_url = mycode.find_url(royal_text) # Call to my script, which is located in the app's folder.
    
        #context_dict = {'skyv_url': skyv_url}
        return render_to_response(skyv_url)
        
    
    else:
        return render_to_response('royals/index.html', {}, context)
forms.py
Python code:
from django import forms

class RoyalForm(forms.ModelForm):
    royal_text = forms.TextField(max_length=6000, help_text="Please paste the royal text here.")
index.html
HTML code:
<!DOCTYPE html>

<html>
    <head>
        <title></title>
    </head>

    <body>
        <h1>Paste Royal text below</ha>
        <form id="royal_entry_form" method="post" action="/royals/">
            {% for hidden in form.hidden_fields %}
            {{ hidden }}
            {% endfor %}

            {% for field in form.visible_fields %}
            {{ field.errors }}
            {{ field.help_text}}<br/>
            {{ field }}
            {% endfor %}
        </form>
        <br/>
        <input class="btn btn-primary" type="submit" name="submit" value="Submit"/>
    </body>

</html>
I'm guessing this can be fixed by altering a few lines. Any ideas? I'm not sure how databases work or fit in. Do I need a database to do simple tasks with webapps? Do I need to set up models.py?

Dominoes fucked around with this message at 22:54 on Nov 6, 2013

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

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 :)

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

Dominoes posted:

views.py
Python code:
from django.shortcuts import render_to_response
from django.template import RequestContext

from royals import mycode

def index(request):
    context = RequestContext(request)
    
    if request.method == 'POST':
        royal_text = royal_form_entry.Text()
        skyv_url = mycode.find_url(royal_text) # Call to my script, which is located in the app's folder.
    
        #context_dict = {'skyv_url': skyv_url}
        return render_to_response(skyv_url)
        
    
    else:
        return render_to_response('royals/index.html', {}, context)
I'm guessing this can be fixed by altering a few lines. Any ideas? I'm not sure how databases work or fit in. Do I need a database to do simple tasks with webapps? Do I need to set up models.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:
from django.shortcuts import render_to_response
from django.template import RequestContext
from royals.forms import RoyalForm

from royals import mycode

def index(request):
    context = RequestContext(request)
    
    if request.method == 'POST':
        form = RoyalForm(request.POST)
        if form.is_valid():
            royal_text = form.cleaned_data['royal_text']
            skyv_url = mycode.find_url(royal_text) # Call to my script, which is located in the app's folder.
    
            #context_dict = {'skyv_url': skyv_url}
            return render_to_response('template.html', skyv_url)
    else:
        form = RoyalForm() # No Data, an empty form  
   
    # this is outside the if else, that way if the form is not valid it renders with the invalid data errors

    return render_to_response('royals/index.html', {"form": form}, context)

edit: formatting broke

Maluco Marinero fucked around with this message at 00:05 on Nov 7, 2013

Baby Nanny
Jan 4, 2007
ftw m8.

fletcher posted:

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?

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.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

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.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
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.

Pollyanna
Mar 5, 2005

Milk's on them.


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?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

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.

Pollyanna
Mar 5, 2005

Milk's on them.


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?

Baby Nanny
Jan 4, 2007
ftw m8.

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.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

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.

Adbot
ADBOT LOVES YOU

Pollyanna
Mar 5, 2005

Milk's on them.


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!

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply