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
Pollyanna
Mar 5, 2005

Milk's on them.


The March Hare posted:

Erghhh, can you paste the response from echo $PATH because I have no idea what is going on.

code:
Rebeccas-MacBook-Pro:~ rebecca$ echo $PATH
/opt/local/bin:
/opt/local/sbin:
/Users/rebecca/.rvm/gems/ruby-2.0.0-p247/bin:
/Users/rebecca/.rvm/gems/ruby-2.0.0-p247@global/bin:
/Users/rebecca/.rvm/rubies/ruby-2.0.0-p247/bin:
/Users/rebecca/.rvm/bin:
/Users/rebecca/anaconda/bin:
/Library/Frameworks/Python.framework/Versions/2.7/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/usr/local/bin:
/opt/X11/bin:
/usr/local/git/bin:
/usr/texbin:
/opt/sm/bin:
/opt/sm/pkg/active/bin:
/opt/sm/pkg/active/sbin
Here's the actual .bash_profile contents:

http://pastebin.com/DkWrGNuw

Adbot
ADBOT LOVES YOU

The March Hare
Oct 15, 2006

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

Pollyanna posted:

code:
Rebeccas-MacBook-Pro:~ rebecca$ echo $PATH
/opt/local/bin:
/opt/local/sbin:
/Users/rebecca/.rvm/gems/ruby-2.0.0-p247/bin:
/Users/rebecca/.rvm/gems/ruby-2.0.0-p247@global/bin:
/Users/rebecca/.rvm/rubies/ruby-2.0.0-p247/bin:
/Users/rebecca/.rvm/bin:
/Users/rebecca/anaconda/bin:
/Library/Frameworks/Python.framework/Versions/2.7/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/usr/local/bin:
/opt/X11/bin:
/usr/local/git/bin:
/usr/texbin:
/opt/sm/bin:
/opt/sm/pkg/active/bin:
/opt/sm/pkg/active/sbin
Here's the actual .bash_profile contents:

http://pastebin.com/DkWrGNuw

Ah, you used macports. FWIW you should use homebrew instead. I have no idea what you did specifically but if you try removing the /Library/Frameworks/Python.framework/Versions/2.7/bin line from your $PATH variable, you should revert to using the osx system-wide installation which shouldn't be broken, unless you did something really really awful.

Also, remove the line in your .bash_profile that adds that directory to the path, or it will keep adding it every time you reboot/restart terminal.

The March Hare fucked around with this message at 03:44 on Oct 19, 2013

Pollyanna
Mar 5, 2005

Milk's on them.


Thankfully, I haven't done anything really really awful (yet).

I gave up and reinstalled 2.7.5 using the .mkpg. Now it works! And all my installed modules are still around. I still don't know what happened or why, but I think I'm gonna avoid using virtualenv for now.

Thanks for the help. When you mentioned stuff about paths I started thinking "maybe the installation I'm using got hosed", rooted around in the system files and that helped me figure it out. :) So I'm also probably going to uninstall MacPorts, since I don't even remember what it was for.

The March Hare
Oct 15, 2006

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

Pollyanna posted:

Thankfully, I haven't done anything really really awful (yet).

I gave up and reinstalled 2.7.5 using the .mkpg. Now it works! And all my installed modules are still around. I still don't know what happened or why, but I think I'm gonna avoid using virtualenv for now.

Thanks for the help. When you mentioned stuff about paths I started thinking "maybe the installation I'm using got hosed", rooted around in the system files and that helped me figure it out. :) So I'm also probably going to uninstall MacPorts, since I don't even remember what it was for.

Macports is a package manager, it helps you install things like git easily. But it is a bit worse than homebrew in my (and most people's) opinions, so you should use homebrew. You should also not give up on virtualenv as it is one of the most important habits to get into early, as it prevents you from really spectacularly loving things up and generally makes it much easier to work going into the future. You won't see much tangible benefit in this moment, but you will down the line. It is worth spending however long reading and rereading virtualenv documentation/tutorials or whatever to understand it.

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

Pythagoras a trois
Feb 19, 2004

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

Pollyanna posted:

Thankfully, I haven't done anything really really awful (yet).

I gave up and reinstalled 2.7.5 using the .mkpg. Now it works! And all my installed modules are still around. I still don't know what happened or why, but I think I'm gonna avoid using virtualenv for now.

Did you try exiting your terminal and reopening it? Serious question, the venv should have been tied to your terminal and shouldn't exist in a new terminal instance, despite the missing environment folder.

Also, definitely grab a developer next time you start a project and have them walk you through venv, because it's incredibly easy to use and a lot of devs can't imagine developing without it. It'll be like three minutes of their time, and if they're not a lovely person, they'll be happy to show you how friggin awesome it makes starting new projects or dealing with more than one project. Mainly because having a clean environment lets you play with a ton of really well developed toys without fear of breaking anything you can't easily remove from your system.


fletcher posted:

If I leave a field blank, I get a nice little This field is required. error message. If I put whitespace in there, it gets around the standard validation and does not throw that same error message.

Some googling led me to this ticket where they concluded that is how the behavior will remain. I can't quite figure out how to implement that behavior myself though. I ended up with something like this:

code:
class Whatever(models.Model):
    awesome_field = models.CharField(max_length=100)

    def clean(self):
        strip_fields = [ 'awesome_field' ]

        for field in strip_fields:
            if getattr(self, field) is not None:
                setattr(self, field, getattr(self, field).strip())
It seems to strip the whitespace...but it's not throwing the This field is required. message like I thought it would. What am I doing wrong?

Edit: I also confused model validation with form validation. The post below me explains it in better detail
\/\/

Pythagoras a trois fucked around with this message at 19:24 on Oct 21, 2013

Pumpkin Pirate
Feb 2, 2005
???????

fletcher posted:

If I leave a field blank, I get a nice little This field is required. error message. If I put whitespace in there, it gets around the standard validation and does not throw that same error message.

Some googling led me to this ticket where they concluded that is how the behavior will remain. I can't quite figure out how to implement that behavior myself though. I ended up with something like this:

code:
class Whatever(models.Model):
    awesome_field = models.CharField(max_length=100)

    def clean(self):
        strip_fields = [ 'awesome_field' ]

        for field in strip_fields:
            if getattr(self, field) is not None:
                setattr(self, field, getattr(self, field).strip())
It seems to strip the whitespace...but it's not throwing the This field is required. message like I thought it would. What am I doing wrong?

The check for required fields being empty is done by the individual form fields. Form field cleaning is the first step of form cleaning, which happens before model cleaning, so by the time you're stripping the whitespace off, the check has already happened and succeeded.

You could simply check after you've stripped the field, and raise a ValidationError if it's blank, but I think the expected way to do something like this is with validators. You would write a function that raises ValidationError with the "required" message if it's given a string of only whitespace, and then pass it to the field constructor for awesome_field.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Pumpkin Pirate posted:

The check for required fields being empty is done by the individual form fields. Form field cleaning is the first step of form cleaning, which happens before model cleaning, so by the time you're stripping the whitespace off, the check has already happened and succeeded.

You could simply check after you've stripped the field, and raise a ValidationError if it's blank, but I think the expected way to do something like this is with validators. You would write a function that raises ValidationError with the "required" message if it's given a string of only whitespace, and then pass it to the field constructor for awesome_field.

Thanks for the input guys. I suppose I'll go with the validator. It really seems like this should be the default behavior in Django though. I mean who would actually want to store whitespace as a value for a required field?

Also, is there some convention for where the code for custom validators should live?

Pythagoras a trois
Feb 19, 2004

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

fletcher posted:

Thanks for the input guys. I suppose I'll go with the validator. It really seems like this should be the default behavior in Django though. I mean who would actually want to store whitespace as a value for a required field?

Also, is there some convention for where the code for custom validators should live?

Now the answer I was trying to give is correct!

The long answer is to read through this surprisingly well documented aspect of django: https://docs.djangoproject.com/en/dev/ref/forms/validation/

The short answer is to modify your forms (preferably for this sort of thing you'd be using modelforms) and copy/paste/adjust to taste:
code:
from django import forms

class WhateverForm(models.ModelForm):

    class Meta:
        model = awesome_model

    def clean_awesome_field(self):
        data = self.cleaned_data['awesome_field']
        for x in 'thequickbrownfoxjumpsoverthelazydogTHEQUICKBROWNFOXJUMPSOVERTHELAZYDOG':
            if data.find(x) != -1:
                return data
        raise forms.ValidationError("Your username is total poo poo man")
        return data

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Hmmm I'm not actually using any ModelForms, since all my froms post to Django REST Framework endpoints. That's why I was trying to do it at the model level.

The March Hare
Oct 15, 2006

Je rêve d'un
Wayne's World 3
Buglord
This just popped up on HN, I skimmed it and it looks like a pretty good resource for newcomers.

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

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.

Thermopyle
Jul 1, 2003

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

I almost posted this in the general programming thread, but I think I'll ask here first...

People will be able to get API keys from the web site I'm working on so that I can monitor/throttle/revoke the REST API usage. I'm also wanting to use the API in my AngularJS frontend. The issue is that anyone with half a brain can get the key I use for the frontend from the page source.

My current thoughts on making this harder for them is figuring out how to use REST Framework to assign temporary API keys to each site visitor using Django's anonymous user sessions (or the user session if it's a logged-in user). That way, someone can't just rip the API key out of the page source and go on their merry way.

Useful idea or just wasting my time? Any other thoughts?

Pollyanna
Mar 5, 2005

Milk's on them.


Cheekio posted:

Did you try exiting your terminal and reopening it? Serious question, the venv should have been tied to your terminal and shouldn't exist in a new terminal instance, despite the missing environment folder.

Yep, I did. I closed the Terminal window, exited Terminal entirely, checked my PYTHONPATH, none of it worked. Bizarre, but that's what happened. :confused:

And yeah, I'll try out venv again, but this time I'll read the documentation first...

MonkeyMaker
May 22, 2006

What's your poison, sir?

Thermopyle posted:

I almost posted this in the general programming thread, but I think I'll ask here first...

People will be able to get API keys from the web site I'm working on so that I can monitor/throttle/revoke the REST API usage. I'm also wanting to use the API in my AngularJS frontend. The issue is that anyone with half a brain can get the key I use for the frontend from the page source.

My current thoughts on making this harder for them is figuring out how to use REST Framework to assign temporary API keys to each site visitor using Django's anonymous user sessions (or the user session if it's a logged-in user). That way, someone can't just rip the API key out of the page source and go on their merry way.

Useful idea or just wasting my time? Any other thoughts?

Tie the API keys to a domain? They might get yours, but it only works coming from your domain (I know that's not super-secure, but giving each user a temporary API key is probably gonna drive you nuts).

Thermopyle
Jul 1, 2003

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

MonkeyMaker posted:

Tie the API keys to a domain? They might get yours, but it only works coming from your domain (I know that's not super-secure, but giving each user a temporary API key is probably gonna drive you nuts).

That's actually a pretty good idea. None of this is really super-secure, but it seems like it's worth putting at least some effort in to it.

If I start getting a big enough mismatch between site visits and API hits, I can always move on to figuring out how to do temporary API keys or something.

Thermopyle
Jul 1, 2003

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

I implemented simple domain checking for token users. You can see the code here.

Specify a list of usernames who should be validated against domain names in settings.FRONTEND_USERS and a list of valid domains in settings.FRONTEND_DOMAINS.

Use DomainAndTokenAuthentication in place of TokenAuthentication in your Django Rest Framework configuration.

MonkeyMaker
May 22, 2006

What's your poison, sir?

Thermopyle posted:

I implemented simple domain checking for token users. You can see the code here.

Specify a list of usernames who should be validated against domain names in settings.FRONTEND_USERS and a list of valid domains in settings.FRONTEND_DOMAINS.

Use DomainAndTokenAuthentication in place of TokenAuthentication in your Django Rest Framework configuration.

So you'll have to change your settings and restart your Python process every time you modify the list of approved users or domains...

Thermopyle
Jul 1, 2003

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

MonkeyMaker posted:

So you'll have to change your settings and restart your Python process every time you modify the list of approved users or domains...

Yeah, I'm not concerned about that as I don't foresee that being something that happens more than once or twice.

Domain checking isn't something that will be done for regular not-my-web-client API users.

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.

The March Hare
Oct 15, 2006

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

Dominoes posted:

I'm working through this ATM - it's excellent. Detailed, acts as a tutorial while explaining everything, organized structure.

Glad to hear that it is actually helpful. How would the thread feel about collaborating on a new OP? The web design & development thread recently spent a while hacking out a new one on a google doc, and the current Django thread OP is pretty out of date. Plus there have been many excellent resources cropping up in the past few months, so I feel we could improve upon it quite a bit.

Thermopyle
Jul 1, 2003

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

The March Hare posted:

Glad to hear that it is actually helpful. How would the thread feel about collaborating on a new OP? The web design & development thread recently spent a while hacking out a new one on a google doc, and the current Django thread OP is pretty out of date. Plus there have been many excellent resources cropping up in the past few months, so I feel we could improve upon it quite a bit.

This sounds like a good idea. The web thread ended up with a pretty good OP.

fuf
Sep 12, 2004

haha
A new OP would be great - I remember getting confused by that tutorial a while back (I think it's outdated now?). I'd help if I could but I don't really know anything about Django. :v:

I've got a new pet project - it's a proofreading site where students will fill in a form, upload an essay, and then login to keep track of its status.

I'm ok with front-end website design, and I've been managing my own VPS for a while, but so far the bit in the middle (basically anything involving databases) has been locked in a box called "WordPress".

I spent some time with Django a while ago, but I've forgotten most of it. I think I used GSWD, but I didn't really have a specific project in mind so I never got beyond "make a blog".

With that in mind I am trying to decide between:
GSWD
http://www.tangowithdjango.com/book/ (based on Dominoes' endorsement above)
"Test-driven web development with Python" (posted a few pages ago - does anyone have an opinion?)

It's the "test-driven" stuff that is giving me pause. How big a deal is it really? Is it a case of "harder to learn but better in the long run"? Is it worth learning that way right from the beginning? I wanna do things right but I also don't wanna go overboard for my first project.

Opinions welcome. :)

Ahz
Jun 17, 2001
PUT MY CART BACK? I'M BETTER THAN THAT AND YOU! WHERE IS MY BUTLER?!
A little help / advice is needed here.

I am getting back into web development since before the days of nice frameworks and decided to learn Python and use Django to get my web app going. My app has quite a few e-commerce features, but the cart/ordering/shipping/tracking aspect of my app is maybe 20% of the code, the rest is based on custom business logic. My question is this:

I've done some research on Django packages like Oscar, Satchmo, Django-shop etc. heavyweight to lightweight packages. But since I have quite a bit of design that goes beyond simple cart/ordering logic: Does it make sense to learn how to integrate a new package into my design vs. roll my own? I’ve done shopping cart/etc before, but I would like to shave time off the development if I can. But I am still learning all the ins and outs of Django, the ORM etc. I don’t want to spend 2 weeks learning how to integrate a Django package when I could just spend 2 weeks rolling my own. But maybe I’m mistaking how much work it will take to roll my own cart/ordering/tracking logic.

I have done it before in Java/jsp completely by hand, it was somewhat onerous but I am now running with the assumption that Django will allievate some of the pain I used to go through with all the BS CRUDS, home-made MVC logic I had to do back in 2001.

Thanks!

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

fuf posted:


It's the "test-driven" stuff that is giving me pause. How big a deal is it really? Is it a case of "harder to learn but better in the long run"? Is it worth learning that way right from the beginning? I wanna do things right but I also don't wanna go overboard for my first project.

Opinions welcome. :)

Welcome to dissent on this one but my feeling on TDD is this. Its an excellent tool of you already have a firm idea of what you'll be testing. If you don't know how to build it, which beginners don't, you'll stumble trying figure out what your API is for testing. Figuring out requirements when your not 100% on how to get to them or test them.

I think instead try to write tests as you go so you're sure you're writing testable code, and then see whether you can start to predict what the tests will be before you build them.

That said, once you do get used to it, it is an EXCELLENT way to add features, as you can verify during every step of your coding not only the new feature but also that you didn't break any old features assuming good test coverage, which is kind of key. :)

Thermopyle
Jul 1, 2003

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

Maluco Marinero posted:

Welcome to dissent on this one but my feeling on TDD is this. Its an excellent tool of you already have a firm idea of what you'll be testing. If you don't know how to build it, which beginners don't, you'll stumble trying figure out what your API is for testing. Figuring out requirements when your not 100% on how to get to them or test them.

I think instead try to write tests as you go so you're sure you're writing testable code, and then see whether you can start to predict what the tests will be before you build them.

That said, once you do get used to it, it is an EXCELLENT way to add features, as you can verify during every step of your coding not only the new feature but also that you didn't break any old features assuming good test coverage, which is kind of key. :)

Yeah, this is all good advice.

I think that if you keep testing in mind while your beginning on a project, at some point in large enough projects it becomes natural to write tests in tandem with the actual code. And then even further into the project as things start fleshing out it almost becomes natural to write the tests before you implement the code.

edit: Here's another site on doing TDD with Django: http://www.tdd-django-tutorial.com/

MonkeyMaker
May 22, 2006

What's your poison, sir?
We just talked about TDD on today's recording of the podcast. The general consensus was that TDD is a lot easier on existing code bases, where you know how things are generally going to look, than it is on brand new code where you're kind of making it up as you go along. Also that it's a skill that requires practice, so if you think you want to do it, be prepared to be slow and grumpy until you get good at doing it.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Thermopyle posted:


edit: Here's another site on doing TDD with Django: http://www.tdd-django-tutorial.com/

FYI, that site is / was the precursor to the 'Test Driven Web Development with Python' site / book a few poss up.

Pollyanna
Mar 5, 2005

Milk's on them.


So what's the deal with deploying Django? That link is a couple years old, so have things gotten any better? What's my best bet for deploying it if I'm just trying to see my work finally get on the web? I have deployed Django on Heroku before (with some significant pains), is that my best bet?

Baby Nanny
Jan 4, 2007
ftw m8.

Pollyanna posted:

So what's the deal with deploying Django? That link is a couple years old, so have things gotten any better? What's my best bet for deploying it if I'm just trying to see my work finally get on the web? I have deployed Django on Heroku before (with some significant pains), is that my best bet?

For something simple? Install gunicorn and run your django site via the wsgi file that was generated when you started your project. Then proxy the address it's running on through nginx or apache or whatever. I'm about to head into work so I can't post specifics but googling around for those terms should get you going pretty easy.

Thermopyle
Jul 1, 2003

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

Lumpy posted:

FYI, that site is / was the precursor to the 'Test Driven Web Development with Python' site / book a few poss up.

Forgive me, I'm a moron.


Pollyanna posted:

So what's the deal with deploying Django? That link is a couple years old, so have things gotten any better? What's my best bet for deploying it if I'm just trying to see my work finally get on the web? I have deployed Django on Heroku before (with some significant pains), is that my best bet?

Deploying on Heroku is super, super, super easy. Try asking about whatever issues you are having with that. At what point in the Heroku/Django docs did you get messed up?

The only way I can see someone having issues is if they weren't already using best-practices tools like virtualenv, pip, and git. If you're not using those your issues go beyond deployment.

Pollyanna
Mar 5, 2005

Milk's on them.


Thermopyle posted:

Forgive me, I'm a moron.


Deploying on Heroku is super, super, super easy. Try asking about whatever issues you are having with that. At what point in the Heroku/Django docs did you get messed up?

The only way I can see someone having issues is if they weren't already using best-practices tools like virtualenv, pip, and git. If you're not using those your issues go beyond deployment.

I am using venv, pip and git. Here's where I get stuck.

quote:


Next, configure the application for the Heroku environment, including Heroku’s Postgres database. The dj-database-url module will parse the values of the DATABASE_URL environment variable and convert them to something Django can understand.

Make sure ‘dj-database-url’ is in your requirements file, then add the following to the bottom of your settings.py file:

Python code:
# Parse database configuration from $DATABASE_URL
import dj_database_url
DATABASES['default'] =  dj_database_url.config()

# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# Allow all host headers
ALLOWED_HOSTS = ['*']

# Static asset configuration
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)
With these settings available, you can add the following code to wsgi.py to serve static files in production:

Python code:
from django.core.wsgi import get_wsgi_application
from dj_static import Cling

application = Cling(get_wsgi_application())

I followed those instructions, did the rest, and then when I input "heroku open", well...

This happens.

code:
DatabaseError at /stem/
relation "basica_greeting" does not exist
LINE 1: ...greeting"."id", "basica_greeting"."greeting" FROM "basica_gr...
                                                             ^
Request Method:	GET
Request URL:	http://secret-reef-9309.herokuapp.com/stem/
Django Version:	1.5.5
Exception Type:	DatabaseError
Exception Value:	
relation "basica_greeting" does not exist
LINE 1: ...greeting"."id", "basica_greeting"."greeting" FROM "basica_gr...
                                                             ^
Exception Location:	/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py in execute, line 54
Python Executable:	/app/.heroku/python/bin/python
Python Version:	2.7.4
Python Path:	
['/app',
 '/app/.heroku/python/bin',
 '/app/.heroku/python/lib/python2.7/site-packages/distribute-0.6.36-py2.7.egg',
 '/app/.heroku/python/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg',
 '/app',
 '/app/.heroku/python/lib/python27.zip',
 '/app/.heroku/python/lib/python2.7',
 '/app/.heroku/python/lib/python2.7/plat-linux2',
 '/app/.heroku/python/lib/python2.7/lib-tk',
 '/app/.heroku/python/lib/python2.7/lib-old',
 '/app/.heroku/python/lib/python2.7/lib-dynload',
 '/app/.heroku/python/lib/python2.7/site-packages',
 '/app/.heroku/python/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']
Server time:	Fri, 25 Oct 2013 11:05:13 -0500
I've tracked it down to Django/Heroku not knowing where my database is, but as far as I can tell I did everything correctly. What's going wrong?

If it helps, here's my database settings:

Python code:
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '/Users/rebecca/Desktop/NerdStuff/Python/stem/stemdb',                      # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': '',
        'PASSWORD': '',
        'HOST': '',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for default.
    }
}
And I've got nginx and its WSGI module installed, so I'll play with that too.

MonkeyMaker
May 22, 2006

What's your poison, sir?
So you won't have settings like that for Heroku. Use dj-database-url.

Pardot
Jul 25, 2001




code:
DatabaseError at /stem/
relation "basica_greeting" does not exist
LINE 1: ...greeting"."id", "basica_greeting"."greeting" FROM "basica_gr...
                                                             ^
It seems like your app connected to the database properly, but the database doesn't have the basica_gretting table. Probably the database doesn't have any tables because I'd bet you didn't run the migrations.

You can poke around your database with heroku pg:psql, and \d in psql will show you your tables

An example of a database with a table to compare against yours:

code:
$ heroku pg:psql -a heroku-reception
Time: 95.862 ms
psql (9.3devel, server 9.2.4)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.

d6oqs5jgki26ff=> \d
            List of relations
 Schema |  Name  | Type  |     Owner
--------+--------+-------+----------------
 public | guests | table | vbanftqtycolnw
(1 row)

d6oqs5jgki26ff=> \q
$

Thermopyle
Jul 1, 2003

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


You say you get messed up on the settings part of the heroku instructions, but then say when you enter 'heroku open' it messes up.

Have you done the steps in between those two things? Obviously, you've pushed to heroku at some point, but have you made changes to your code and then not pushed them to heroku?

Also, it looks like you missed the step where you run heroku run python manage.py syncdb.

Pollyanna
Mar 5, 2005

Milk's on them.


Okay, so...

MonkeyMaker posted:

So you won't have settings like that for Heroku. Use dj-database-url.

Right, yeah. What basically happens is that the information in the stuff Heroku wants me to paste in settings.py overwrites the settings I had already made, which is clunky but works fine. That's where dj_database_url comes in, and it's what Heroku uses to refer to a database on their end.

Thermopyle posted:

You say you get messed up on the settings part of the heroku instructions, but then say when you enter 'heroku open' it messes up.

Have you done the steps in between those two things? Obviously, you've pushed to heroku at some point, but have you made changes to your code and then not pushed them to heroku?

Also, it looks like you missed the step where you run heroku run python manage.py syncdb.

Well, I did go check out my web page right after it asks me to "heroku open", so maybe I jumped the gun? :shobon: The steps in between are creating and pushing a git. If I hadn't done that, it wouldn't be on the server at all. (Right?)

Okay, I disabled the Heroku settings, committed and pushed, re-enabled them, committed and pushed, so that's the changes to the code thing down. Everything should be synced up on git. Next is syncing the DB...which works. Let's see what tables are there.

Pardot posted:

You can poke around your database with heroku pg:psql, and \d in psql will show you your tables

An example of a database with a table to compare against yours:

code:
$ heroku pg:psql -a heroku-reception
Time: 95.862 ms
psql (9.3devel, server 9.2.4)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.

d6oqs5jgki26ff=> \d
            List of relations
 Schema |  Name  | Type  |     Owner
--------+--------+-------+----------------
 public | guests | table | vbanftqtycolnw
(1 row)

d6oqs5jgki26ff=> \q
$

Alright, here's what I get when I run heroku pg:psql \d:

code:
                           List of relations
 Schema |               Name                |   Type   |     Owner      
--------+-----------------------------------+----------+----------------
 public | auth_group                        | table    | aqwrnkbntaqkxx
 public | auth_group_id_seq                 | sequence | aqwrnkbntaqkxx
 public | auth_group_permissions            | table    | aqwrnkbntaqkxx
 public | auth_group_permissions_id_seq     | sequence | aqwrnkbntaqkxx
 public | auth_permission                   | table    | aqwrnkbntaqkxx
 public | auth_permission_id_seq            | sequence | aqwrnkbntaqkxx
 public | auth_user                         | table    | aqwrnkbntaqkxx
 public | auth_user_groups                  | table    | aqwrnkbntaqkxx
 public | auth_user_groups_id_seq           | sequence | aqwrnkbntaqkxx
 public | auth_user_id_seq                  | sequence | aqwrnkbntaqkxx
 public | auth_user_user_permissions        | table    | aqwrnkbntaqkxx
 public | auth_user_user_permissions_id_seq | sequence | aqwrnkbntaqkxx
 public | basica_blogpost                   | table    | aqwrnkbntaqkxx
 public | basica_blogpost_id_seq            | sequence | aqwrnkbntaqkxx
 public | basica_greeting                   | table    | aqwrnkbntaqkxx
 public | basica_greeting_id_seq            | sequence | aqwrnkbntaqkxx
 public | basica_projectpost                | table    | aqwrnkbntaqkxx
 public | basica_projectpost_id_seq         | sequence | aqwrnkbntaqkxx
 public | django_admin_log                  | table    | aqwrnkbntaqkxx
 public | django_admin_log_id_seq           | sequence | aqwrnkbntaqkxx
The tables are in fact there, if I'm reading it correctly... We've got a dyno running, the website is up, let's see how it is:

http://retrocombine.herokuapp.com/stem/

:woop: YAY IT'S UP- Oh. :smith: Okay, the database didn't actually migrate. The entries and stuff I had are gone! If I add new ones again...

http://retrocombine.herokuapp.com/stem/

:siren::woop::siren:

Okay, it's up! Looks like it's working now. I guess the database was the issue, and I was getting errors because the tables were empty. The only problem I have is that none of my local stuff transferred over. That's fixable with stuff like blog posts, but more complicated things might not be so easy to restore. Why didn't my local database come over?

edit: Oh, also, I can't test locally or anything. It gives me a database error. I thought you could work both online and offline?

Pollyanna fucked around with this message at 18:26 on Oct 25, 2013

The March Hare
Oct 15, 2006

Je rêve d'un
Wayne's World 3
Buglord
Your data didn't migrate because you didn't do anything that would make that happen. You transferred over the structure of your database, which is found (loosely) in your models.py, but you didn't actually move data over.

e; You can google around for ways to move the data inside of your local app to a remote deployment, there are a bunch of ways to do it and how you go about it will depend on a few factors, like if you used postgresql in your local testing &c.

The March Hare fucked around with this message at 18:31 on Oct 25, 2013

Thermopyle
Jul 1, 2003

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

And the reason the Heroku instructions don't say anything about transferring local data to the remote server is that you're not really supposed to be putting anything you want in production on you dev database.

The March Hare
Oct 15, 2006

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

Thermopyle posted:

This sounds like a good idea. The web thread ended up with a pretty good OP.

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.

Adbot
ADBOT LOVES YOU

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Anybody using AngularJS with your Django application? How's that working out?

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