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
Dominoes
Sep 20, 2007

Is Getting started with Django a good place to learn? Is there a trick to viewing answers on their forums? I get an error at the beginning, when running vagrant up. (ArgumentError: wrong number of argumnets) There are a number of posts about this on the front page of the forum, but the replies/answers are not loading, only the question. Example. Any ideas?

Dominoes fucked around with this message at 03:36 on Jun 2, 2013

Adbot
ADBOT LOVES YOU

Dominoes
Sep 20, 2007

bonds0097 posted:

I don't think it's a good way to start. Its reliance on the Vagrant stuff is unfortunate because you'll probably get stuck there due to mismatch in Ruby/Chef versions. You'll basically be defeated before you even start messing around with Django. :p

Instead, I would recommend the following:

- Follow the official Django Tutorial here: https://docs.djangoproject.com/en/dev/intro/tutorial01/
- Get this awesome book full of best practices: Two Scoops of Django - https://django.2scoops.org/
- Try a more involved tutorial like this one at NetTuts: http://net.tutsplus.com/tutorials/python-tutorials/building-ribbit-with-django/
- Get the basics of Vagrant/Chef here: http://blog.smalleycreative.com/tutorials/setup-a-django-vm-with-vagrant-virtualbox-and-chef/

At that point, I think you could try the GSWD tutorial and actually be able to troubleshoot the issues with Vagrant/Chef yourself (as long as your google is good). And you can reference Two Scoops throughout GSWD and the NetTuts stuff to get some additional perspective and apply principles and practices.

Honestly, I would avoid the 'precise64' and 'precise32' Vagrant boxes like the plague. Instead, get this box: https://dl.dropboxusercontent.com/u/165709740/boxes/precise64-vanilla.box and then manually 'sudo apt-get ruby1.9.1' and 'gem install chef' yourself. That ensures you don't have outdated Ruby/Chef on the VM.

EDIT: Note, I think the GSWD tutorial itself is pretty great. The infrastructure is just lacking. That said, it covers cool stuff like the use of virtual environments, splitting settings files between dev/prod (though it employs the anti-pattern of leaving local settings out of version control, which is a questionable practice), using South for Database migrations, etc.
Thanks. I'm going to take your advice and stick with the official tutorial for now, which doesn't require extra software. I tried the smalley link in your post, and it also gives me a vagrant up error (although a different one). I'll try Two Scoops and NetNuts after finishing the default ones. This is a lot more complicated than I thought! (it looks like it's more complicated than Python itself.)

Someone just posted an identical problem to to mine on the getting started with Django forum - He has vagrant up issues, sees multiple threads about it with answers, but can't see the answers.

Dominoes fucked around with this message at 00:15 on Jun 3, 2013

Dominoes
Sep 20, 2007

MonkeyMaker posted:

Since I don't have SSL on the site, maybe try dropping the 's' on the URL? Works for me.
It looks like answers/replies from this weekend are newer may be showing up, but older ones aren't.

Dominoes
Sep 20, 2007

etcetera08 posted:

I'm working with MonkeyMaker to provide a fully compatible package you can use but if you want to use his VM download from the first lesson as he describes it you can just comment out line 41 of the Vagrantfile and bring up the VM. You may have to remove your old VM from Virtualbox, or you can just move out the .vagrant stuff in the directory if you don't care about having an orphaned VM sitting on your machine.

For the curious, the Vagrantfile was upgrading Chef to a version that breaks with 1.8.x. If you just provision your box with that box's built in version of Chef it will come up fine.
Awesome. I'm still getting the wrong number of arguments error after editing the Vagrantfile. I'm going to finish the official Django tutorial first, then dive into GSWD.

Dominoes
Sep 20, 2007

etcetera08 posted:

Ah, ok, I'll keep looking into it. Should have an update tomorrow.

EDIT: Works for me with only that slight edit. Should be running Chef client 10.14.2. You're probably still trying to provision the VM that already upgraded its own Chef install. Before it crashes out what do your equivalent lines to these say? My guess is that it will say Chef 11.xx.
code:
Running chef-solo...
stdin: is not a tty
[2013-06-05T05:03:05+00:00] INFO: *** Chef 10.14.2 ***
Correct. Chef 11.4.4

Dominoes
Sep 20, 2007

etcetera08 posted:

So, that's your problem. Go in and delete the VM from Virtualbox and then remove all .vagrant artifacts (I think it will be a directory for your version of Vagrant). Then do `vagrant up` again and you should be golden.
Thanks - Vagrant up completed without errors.

Dominoes
Sep 20, 2007

I successfully ran Vagrant up, installed Putty, and successfully (I think) entered Vagrant with SSH, ran 'sudo ./postinstall.sh'. It seemed to complete, with a few messages about not being able to delete directories. Based on going ahead at this point and things not working in the steps after, I think the note on the GSWD page about not seeing shared folders applies. (Was running sudo ./postinstall.sh supposed to dump some files/folders in my directly that has Cheffile and Vagrantfile?) I followed the steps of exiting the SSH, and running 'vagrant halt' and 'vagrant up' from a non-putty terminal. When I ran vagrant up, it showed chef-11.4.4. again, and errored out with 'wrong number of arguments' as before.

Dominoes fucked around with this message at 16:22 on Jun 8, 2013

Dominoes
Sep 20, 2007

Do you pronounced it "earl"?

Dominoes
Sep 20, 2007

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

Dominoes
Sep 20, 2007

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.

Dominoes
Sep 20, 2007

Thanks dude - I think I'll take your advice and give it a shot on my Ubuntu laptop.

Dominoes
Sep 20, 2007

Hey dudes, thanks for the help with Getting Started With Django. I took your try it on Ubuntu and skip Vagrant advice; it's working, and I'm learning.

One of the reasons it was so confusing, is that initially it's not so much a Django tutorial as a complex web development tutorial. GSWD introduces several big concepts together, and for someone new, the distinctions aren't obvious:

-Virtualization
-Heroku / web-app servers
-Unix command line
-Postgresql and databases
-Django/Python
-Git and versioning

After understanding this breakdown and looking up basic tutorials for each, it's starting to click.

Dominoes fucked around with this message at 22:11 on Oct 20, 2013

Dominoes
Sep 20, 2007

The March Hare posted:

This just popped up on HN, I skimmed it and it looks like a pretty good resource for newcomers.

http://www.tangowithdjango.com/book/
Thanks homie.

Dominoes
Sep 20, 2007

The March Hare posted:

This just popped up on HN, I skimmed it and it looks like a pretty good resource for newcomers.

http://www.tangowithdjango.com/book/
I'm working through this ATM - it's excellent. Detailed, acts as a tutorial while explaining everything, organized structure.

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

Dominoes
Sep 20, 2007

Maluco Marinero posted:

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
Thanks, this worked. Additionally, I needed to change the form's inheritance from form.ModelForm to form.Form.

Dominoes
Sep 20, 2007

Has anyone gotten Django working on OpenShift? The tutorials I find lead to HTTP 403 errors.

For example, if I follow this tutorial, the rhc tail dump is as follows:

code:
  
==> python/logs/appserver.log <==
  File "<frozen importlib._bootstrap>", line 1023, in load_module
  File "<frozen importlib._bootstrap>", line 1004, in load_module
  File "<frozen importlib._bootstrap>", line 562, in module_for_loader_wrapper
  File "<frozen importlib._bootstrap>", line 869, in _load_module
  File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
  File "wsgi/application", line 8, in <module>
    virtenv = os.environ['APPDIR'] + '/virtenv/'
File "/var/lib/openshift/528280414382ecf87b0000ca/python//opt/lib/python3.3/os.py", line 669, in __getitem__
    value = self._data[self.encodekey(key)]
KeyError: b'APPDIR'
A fellow at this website fixed this error by changing a line in the application file: virtenv = os.environ['OPENSHIFT_HOMEDIR'] + '/virtenv/'

The resulting tail dump:
code:
==> python/logs/appserver.log <==
    return _LoadSourceCompatibility(name, pathname, file).load_module(name)
  File "<frozen importlib._bootstrap>", line 586, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1023, in load_module
  File "<frozen importlib._bootstrap>", line 1004, in load_module
  File "<frozen importlib._bootstrap>", line 562, in module_for_loader_wrapper
  File "<frozen importlib._bootstrap>", line 869, in _load_module
  File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
  File "wsgi/application", line 14, in <module>
    execfile(virtualenv, dict(__file__=virtualenv))
NameError: name 'execfile' is not defined
Based on this stack overflow thread, I changed the offending line to exec(compile(open(virtualenv).read(), virtualenv, 'exec'), dict(__file__=virtualenv))

New tail dump:
code:
==> python/logs/appserver.log <==
    signals.request_started.connect(reset_queries)
  File "/var/lib/openshift/528280414382ecf87b0000ca/python/virtenv/venv/lib/python3.3/site-packages/Django-1.6-py3.3.egg/django/dispatch/dispatcher.py", line 88, in connect
    if settings.DEBUG:
  File "/var/lib/openshift/528280414382ecf87b0000ca/python/virtenv/venv/lib/python3.3/site-packages/Django-1.6-py3.3.egg/django/conf/__init__.py", line 54, in __getattr__
    self._setup(name)
  File "/var/lib/openshift/528280414382ecf87b0000ca/python/virtenv/venv/lib/python3.3/site-packages/Django-1.6-py3.3.egg/django/conf/__init__.py", line 49, in _setup
    self._wrapped = Settings(settings_module)
  File "/var/lib/openshift/528280414382ecf87b0000ca/python/virtenv/venv/lib/python3.3/site-packages/Django-1.6-py3.3.egg/django/conf/__init__.py", line 132, in __init__
    % (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'PROJECTNAME.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named 'PROJECTNAME'

Edit: got a template working by changing 'PROJECTNAME' to my project name. However, when I try to apply it to my existing Django project, I get a 503 with tail:
code:
ImportError: Could not import settings 'myproject.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named 'myproject'
The application.py files and openshift-related directory structure of the working template and broken project seem similar. There's definitely a myproject.settings.py file where it should be.
edit a

Dominoes fucked around with this message at 21:49 on Nov 12, 2013

Dominoes
Sep 20, 2007

Yea - that version doesn't even get past the APPDIR problem. This is getting weird, and I can't figure out why some test projects I'm creating work and others 503 with the import error. Ie: If I start a clean django project in my app's wsgi directory, it works. If I copy and paste it, and change the project name in all of the basic django files, and in the application file, it works. If I name is the same thing as the project I actually want to use as a step prior to pasting the code in, it doesn’t. I'd use Heroku, which just works, but I think my work's firewall doesn't block openshift apps, but does block heroku apps.

Dominoes fucked around with this message at 14:59 on Nov 13, 2013

Dominoes
Sep 20, 2007

Suspicious Dish posted:

Try #openshift on Freenode?
Turns out Openshift needs the path for templates to be os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir).

TangoWithDjango demonstrates cwd, which is what was screwing it up. It has to do with Openshift's nested directory structure.


Here's an example working application file:

Python code:
#!/usr/bin/python
import os, sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'modulenamegoeshere.settings'
sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'wsgi',
    'modulenamegoeshere'))

virtenv = os.environ['OPENSHIFT_HOMEDIR'] + '/virtenv/'
os.environ['PYTHON_EGG_CACHE'] = os.path.join(virtenv, 'lib/python3.3/site-packages')
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')

try:
    exec(compile(open(virtualenv).read(), virtualenv, 'exec'), dict(__file__=virtualenv))
except IOError:
    pass

#
# IMPORTANT: Put any additional includes below this line.  If placed above this
# line, it's possible required libraries won't be in your searchable path
#
from django.core.handlers import wsgi
application = wsgi.WSGIHandler()
The virtenv assignment has been changed from the outdated official instructions, and the exec line has been changed for Python3 compatibility.

Dominoes
Sep 20, 2007

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:
class InputForm(forms.Form):
    fields = []

    fields.append(forms.CharField(widget=forms.Textarea(attrs={
        'cols': 75, 'rows': 30}), max_length=10000, help_text="Paste text here:"))

    extra_fields = 3
    for field in range(extra_fields):
        fields.append(forms.CharField(widget=forms.Textarea(attrs={
            'cols': 75, 'rows': 30}), max_length=10000,
            help_text="Enter additional text here:"))

    for field in fields:
        self.visible_fields.append(field) # attemped fix; not working.    
I'm using this standard bit in my template:

Python code:
            {% for hidden in form.hidden_fields %}
                {{ hidden }}
            {% endfor %}

            {% for field in form.visible_fields %}
                {{ field.errors }}
                {{ field.help_text}}<br/>
                {{ field }}
            {% endfor %}

Dominoes fucked around with this message at 14:21 on Dec 7, 2013

Dominoes
Sep 20, 2007

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.

Dominoes
Sep 20, 2007

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.

Dominoes
Sep 20, 2007

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

Dominoes
Sep 20, 2007

Thanks fletcher - got it sorted using the first two lines you linked, after adding south to my installed apps, and running convert_to_south.

Dominoes
Sep 20, 2007

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:
project
    project
        settings.py etc
    app
        normal django files and custom code here
    templates
        my templates are here
    static
        stylesheet is here
    mydatabase.db
For openshift, I modify the directory as follows:
code:
openshift appname
    wsgi
        project
            project
                settings.py etc
            app
                normal django files and custom code here
            templates
                my templates are here
            static
                stylesheet is here (NOT WORKING)
            mydatabase.db (NOT WORKING)
Relevant bits of my setup.py file:

Python code:
BASE_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir)
STATIC_PATH = os.path.join(BASE_DIR, 'static')
DATABASE_PATH = os.path.join(BASE_DIR, 'mydatabase.db')

...

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': DATABASE_PATH,
    }

...

STATIC_ROOT = ''
STATIC_URL = '/static/'

Any ideas? It works fine when running locally.

Dominoes fucked around with this message at 18:49 on Jan 16, 2014

Dominoes
Sep 20, 2007

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!
TWD's fantastic, and current.

Dominoes
Sep 20, 2007

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.

Dominoes
Sep 20, 2007

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".
Shot in the dark: Are you using read() instead of chunk()?

Dominoes
Sep 20, 2007

Muslim Wookie posted:

I'm looking at creating an intranet page of sorts, that needs to be able to auth users against AD, read data from a DB and create .docx documents using, in part, information provided by users via forms on the intranet page.

At the risk of being laughed off this planet, I'm not a professional coder, having pretty much done just CodeAcademy python and have a few reference books at home.

Would Django be the right place for me to start?
Yea, it'll be fine for that. Python's xml.etree.ElementTree should work for the .dox documents.

Dominoes
Sep 20, 2007

Ahz posted:

Pycharm is a pretty nifty Javascript debugger. It hooks right into a firefox/chrome instance and gives you some pretty great debug tools, breakpoints etc.
Is there a way to get it to recognize javascript in html documents that use django's template inheritance (ie {% block %} syntax)? Ie have introspection, color-coding etc.

Dominoes fucked around with this message at 18:46 on Apr 27, 2014

Dominoes
Sep 20, 2007

I'm using the paid version.

Dominoes
Sep 20, 2007

Example where PyCharm doesn't do magic on JS

It does magic on the HTML and Django in the file, and does magic on everything for the file it extends.

Dominoes
Sep 20, 2007

Thermopyle posted:

I won't be on my PyCharm-havin' PC until tomorrow, but I bet you it's because it's not wrapped in script tags in that file. You may have them in the base file/block, but PyCharm doesn't introspect templates deeply enough to figure that out.

Throw some script tags in there to check...or I'll do it tomorrow.

I didn't look at your JS too closely, but I'd probably just insert another block in your base file to take the js from imagery.html and then use the script tags.

Hey, that was it. I'll figure out how to rearrange the file to make it work, if appropriate. Ideally the JS would be in a separate static file, but the host I'm using, Openshift, doesn't play nice with those.

Dominoes fucked around with this message at 10:16 on Apr 29, 2014

Dominoes
Sep 20, 2007

Is there a recommended project structure for current versions of Django? Searching shows several different layouts. Mostly, I'm confused about where to put static/(staticfiles/?) and templates/.

Current setup:

code:
-project
    -project
        __init__.py
        settings.py
        urls.py
        views.py
        wsgi.py
    -static
        -app
    -templates
        -app
    -App
    -manage.py    
It looks like most tutorials are recommending referencing the project directory in settings.py as 'os.path.dirname(os.path.abspath(__file__))', but I need to use a pardir() in there to make it work. Does this mean the static and template dirs should be inside project/project instead of up a level like I'm using? Should static files be in 'static/' or 'staticfiles/' ?

Dominoes
Sep 20, 2007

Thanks - why do many deployment guides, such as this, recommend referring to the project path as this:?
PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))

With the layout I described, this is required instead, which I found out by trial and error:
PROJECT_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir)

For the initial line to work, wouldn't static/, templates/ etc have to be in the project/project directory?

Dominoes
Sep 20, 2007

Thermopyle posted:

Why do you think you require the second line? What exactly goes wrong if you use the first?

I recommend picking up Two Scoopes of Django. It addresses a lot of this stuff.
The first line points to a (nonexistant) 'project/project/static' directory when used with the rest of these guides. My actual static (or templates) directory is up a level in 'project/static'.

ie: in the guide I linked:

Python code:
BASE_DIR = os.path.dirname(os.path.abspath(__file__))

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

Dominoes fucked around with this message at 21:20 on May 6, 2014

Dominoes
Sep 20, 2007

Thanks - I redid my settings.py according to the 1.6 default. It looks like its method of 'BASE_DIR = os.path.dirname(os.path.dirname(__file__))' does the same as my parent method. I think the deployment guides I was referencing were outdated or nonstandard.

I like how in Monkey's example, the app-specific templates are in project/app/templates, instead of project/templates/app. Using the latter, you'd reference a template like so:

code:
return render_to_response('app/index.html', context_dict, context)
How do you do the same with the project/app/templates structure?

Do you add add 'BASE_DIR' to TEMPLATE_DIRS in settings, then reference the template as 'app/templates/index.html'? That seems to work. It looks like not adding to TEMPLATE_DIRS, and not adding '/template', but nesting the templates in an additional app folder, ie project/app/templates/app/index.html works too. Cleaner in some ways, but unnecessarily buried.

Dominoes fucked around with this message at 18:43 on May 8, 2014

Dominoes
Sep 20, 2007

MonkeyMaker posted:

My usual layout is something like:
Thanks for posting this.

Thermopyle posted:

The reason you should nest an extra app directory inside templates is because all of the template directories throughout your project are namespaced together by the app_directories.Loader. So, if you had project/app1/templates/index.html and project/app2/templates/index.html, project/templates/index.html and then you referenced index.html, Django doesn't know which one you want.

It would be better if you didn't have to nest that extra app directory, but ~history~.

So, to answer your question, you don't add your base dir to TEMPLATE_DIRS, you use project/app/templates/app/index.html. This is how the django.template.loaders.app_directories.Loader finds the template. (That loader is part of the default configuration for TEMPLATE_LOADERS).
Thanks, I'll go with this from now on.

Dominoes
Sep 20, 2007

Looking for wisdom on moving from Sqlite to Postgres. I have a webapp that helps track things at work. It uses a Sqlite database, and is running on Openshift.

Openshift has been a pain in the rear end. It works, but I have multiple issues, ie no static files, convoluted directory structure/update process, and wrong system time. These issues might be fixable, but no there's no documentation or support available, so it's a lost cause.

I'm moving to Heroku, which doesn't support SQlite. I've got Postgres working on Heroku, and on my personal computer. I need to migrate my database, which has 1000s of records. With Sqlite, it was easy to just upload/download the file - I don't think I can do that with Postgres. Locally, I've been able to use Django's dumpdata and load data to export the data as json. I can't seem to do that on Heroku. If I use 'heroku run python manage.py loaddata', it can't find the file. (the file's local) How should I approach this?

Dominoes fucked around with this message at 20:50 on May 16, 2014

Adbot
ADBOT LOVES YOU

Dominoes
Sep 20, 2007

Thanks. I went with your second option, and it worked! Connecting directly seems like a pretty powerful and useful feature.

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