Skip to content

WebFaction Django Python tips notes

Michael Hulse edited this page Jan 7, 2015 · 30 revisions

Misc. notes working my way through Django/Python dev setup on WebFaction.


Default Python:

Add this to .bash_profile:

# Default Python
# http://docs.webfaction.com/software/python.html#creating-a-python-alias
alias python=python3.4

Reload your changes:

$ source ~/.bash_profile

Python's venv

First, in your home directory, make:

$ mkdir -p ~/.virtualenvs

In your .bash_profile, add this:

# Default pyvenv
alias pyvenv=pyvenv-3.4

Create the environment:

$ pyvenv ~/.virtualenvs/repower

Activate:

$ source ~/.virtualenvs/repower/bin/activate

Deactivate (when activated):

$ deactivate

Note, pip comes with Python 3.4 pyvenv:

$ which pip
~/.virtualenvs/repower/bin/pip

Nice!

To make it quick, add an alias to your .bash_profile:

# Simplify pyvenv activation for "repower" environment:
alias repower='source ~/.virtualenvs/repower/bin/activate'

And then reload:

source ~/.bash_profile 

Now:

$ repower

Now you can use pip (in the venv) to install dependencies/packages.


Specify a default Django settings file using pyvenv

Append this to ~/username/.virtualenvs/repower/bin/activate:

export DJANGO_SETTINGS_MODULE="repower.settings.production"
echo $DJANGO_SETTINGS_MODULE

And:

$ source ~/.bash_profile

Now, when activating the virtual environment, you'll see the settings echoed upon instantiation:

$ repower
repower_root.settings.production
(repower) [mhulse@web419 repower]$ source ~/.bash_profile 

SSH key bitbucket

Do this:

$ ssh-keygen
# No pass (though, it's recommended)
$ chmod 644 ~/.ssh/id_rsa.pub
$ ssh-agent bash
$ ssh-add

Now we need to add the public key to BitBucket

  1. Log in to Bitbucket.
  2. Click on your user icon and choose ‘Manage account‘ tab
  3. Under the ‘SSH keys‘ pane, copy and paste cat ~/.ssh/id_rsa.pub | pbcopy the text from your public key file (~/.ssh/id_rsa.pub) into the text input box and click the ‘Add key’ button.
  4. In the .ssh directory, add a file named config (no extension) with these contents:
Host bitbucket.org
IdentityFile ~/.ssh/id_rsa
  1. Run $ source ~/.bash_profile
  2. Check if everything is working: $ ssh -T [email protected]; you should get this back:
conq: logged in as tutorials.
You can use git or hg to connect to Bitbucket. Shell access is disabled.

Verify that the command returns your account name.

  1. Add this to your repo's config:
[remote "origin"]
   url = [email protected]:repower/repower.git
   fetch = +refs/heads/*:refs/remotes/origin/*
  1. Log out and back in to the server. You should now be able to push/pull without passwords.
Clone this wiki locally