SaltyCrane Blog — Notes on JavaScript and web development

Card store project #3: Installing Satchmo, part 2

Here are my initial steps in setting up my Satchmo store. It is meant to be a continuation of my previous post, Installing Satchmo, Django, PostgreSQL, and Apache on Ubuntu at Slicehost. I am using Satchmo version 0.8, released 2008-11-25. I am combining the instructions from the Satchmo documentation and Bruce's blog post. I'm sorry if this post is redundant-- I just wanted to have all the notes in one place for my reference. Almost all the instructions here are from one of these two sources.

Here is my final project directory structure mostly copied from Bruce's post:

HandsOnCards/
`-- handsoncards/
    |-- __init__.py
    |-- bin/
    |-- local_settings.py
    |-- manage.py*
    |-- satchmo.log
    |-- settings.py
    |-- static/
    |   |-- css/
    |   |   |-- blackbird.css*
    |   |   `-- style.css
    |   |-- images/
    |   |   |-- blackbird_icons.png
    |   |   |-- blackbird_panel.png
    |   |   |-- productimage-picture-default.jpg
    |   |   `-- sample-logo.bmp
    |   |-- js/
    |   |   |-- blackbird.js
    |   |   |-- jquery.cookie.js
    |   |   |-- jquery.form.js
    |   |   |-- jquery.js
    |   |   |-- satchmo_checkout.js
    |   |   |-- satchmo_core.js
    |   |   |-- satchmo_pay_ship.js
    |   |   `-- satchmo_product.js
    |   `-- protected/
    |-- store/
    |   |-- __init__.py
    |   |-- models.py
    |   |-- templatetags/
    |   |   `-- __init__.py
    |   |-- urls.py
    |   `-- views.py
    |-- templates/
    |   `-- store/
    `-- urls.py

Set up project

  • Create directory structure:
    cd /srv
    mkdir HandsOnCards
    cd HandsOnCards
    /srv/Django-1.0.2-final/django/bin/django-admin.py startproject handsoncards
    cd handsoncards
    mkdir bin
    mkdir -p templates/store
    ./manage.py startapp store
    mkdir -p store/templatetags
    touch store/templatetags/__init__.py
    
  • Create log file
    touch satchmo.log
    chmod 666 satchmo.log
  • Create the cache directory:
    mkdir django_cache
    chmod 777 django_cache
  • Copy settings files:
    cp /srv/satchmo-0.8/satchmo/local_settings-customize.py local_settings.py
    cp /srv/satchmo-0.8/satchmo/settings-customize.py settings.py
  • Set the Python path:
    export PYTHONPATH=/srv/python-packages:/srv/HandsOnCards
  • Copy static files:
    python manage.py satchmo_copy_static
    chmod 777 static/css
    chmod 777 static/images
    chmod 777 static/js
  • Set the root URLconf. Edit settings.py:
    ROOT_URLCONF = 'handsoncards.urls'
  • Create handsoncards/store/urls.py to only contain the following:
    from django.conf.urls.defaults import *
    from satchmo.urls import urlpatterns
  • Edit handsoncards/urls.py to only contain the following:
    from django.conf.urls.defaults import *
    from handsoncards.store.urls import urlpatterns
  • Configure templates. Edit local_settings.py:
    SATCHMO_DIRNAME = '/srv/python-packages/satchmo'
    DIRNAME = os.path.abspath(os.path.dirname(__file__).decode('utf-8'))
    TEMPLATE_DIRS = (
        os.path.join(DIRNAME, "templates/store"),
        os.path.join(DIRNAME, "templates"),
        os.path.join(SATCHMO_DIRNAME, "templates"),
    )
    (I also commented out TEMPLATE_DIRS in settings.py since this replaces it.)
  • Install the store app. Edit settings.py:
    INSTALLED_APPS = (
      [...]
      'handsoncards.store', #should usually be last
    )
  • From my previous post, use the following database settings in settings.py:
    DATABASE_ENGINE = 'postgresql_psycopg2'
    DATABASE_NAME = 'django_db'
    DATABASE_USER = 'django_user'
    DATABASE_PASSWORD = 'django_password'
    DATABASE_HOST = ''
    DATABASE_PORT = ''

Configure misc. settings

In settings.py:

LOCAL_DEV = False
ADMINS = (
    (Sofeng', [email protected]'),
)
TIME_ZONE = 'America/Los_Angeles'
#LANGUAGE_CODE = 'en-us.utf8'
MEDIA_ROOT = os.path.join(DIRNAME, 'static/')
MEDIA_URL = '/site_media/'
ADMIN_MEDIA_PREFIX = '/admin_media/'
SECRET_KEY = 'yoursecretkeyhere'
SATCHMO_SETTINGS = {
    'SHOP_BASE' : '/shop',
    [...]
}

In local_settings.py:

SITE_DOMAIN = "handsoncards.com"
SITE_NAME = "HandsOnCards.com"
CACHE_BACKEND = "file://" + DIRNAME + "/django_cache"

Test and install data

  • Set the Python path:
    export PYTHONPATH=/srv/python-packages:/srv/HandsOnCards
  • Test Satchmo setup:
    python manage.py satchmo_check
    Results:
    Checking your satchmo configuration.
    Using Django version 1.0.2 final
    Using Satchmo version 0.8
    Your configuration has no errors.
  • Create database tables:
    python manage.py syncdb
    Go ahead and create a superuser
  • Load country data:
    python manage.py satchmo_load_l10n
  • Load US tax table:
    python manage.py satchmo_load_us_tax

Set up httpd.conf and static media links

  • Create symbolic links in /var/www:
    cd /var/www
    ln -s /srv/python-packages/django/contrib/admin/media admin_media
    ln -s /srv/HandsOnCards/handsoncards/static site_media
  • Edit /etc/apache2/httpd.conf:
    <location "/">
        SetHandler python-program
        PythonHandler django.core.handlers.modpython
        SetEnv DJANGO_SETTINGS_MODULE handsoncards.settings
        PythonPath "['/srv/HandsOnCards', '/srv/python-packages'] + sys.path"
        PythonDebug Off
    </location>
    <location "/site_media">
        SetHandler None
    </location>
    <location "/admin_media">
        SetHandler None
    </location>
  • Restart apache:
    /etc/init.d/apache2 restart

View the store

Navigate to http://[your domain or slice ip address]/shop/ in your browser. You should see an empty test store.

Create a Store Configuration

  • Go to http://[your domain or slice ip address]/admin/ and log in.
  • Update the "Site". Click on "Sites". Click on "example.com" and set your domain.
  • Under the "Shop" heading, click on "Store Configurations". Click "Add Store Configuration" and fill in the information.

Create categories and products

  • Create a Category:
    • Next to "Categories", click "Add"
    • Fill in the data
  • Create a Product:
    • Next to "Products", click "Add"
    • Fill in the data

Customize templates and CSS

  • Copy the desired templates from /srv/satchmo-0.8/satchmo/templates to /srv/HandsOnCards/handsoncards/templates/store and edit them.
  • To customize the style, edit handsoncards/static/css/style.css

Redirect '/' to '/shop/'

  • Edit handsoncards/urls.py as follows:
    from django.conf.urls.defaults import *
    from handsoncards.store.urls import urlpatterns
    
    urlpatterns += patterns(
        '',
        (r'^$', 'django.views.generic.simple.redirect_to', {'url': '/shop/'}),
    )

Comments


#1 Eliot commented on :

Here is a question I received through email:

Thanks for the great guide. It is really useful.

I am installing satchmo 0.8 on python 2.5.2 and Django 1.0.2 on Ubuntu 8.04. I have no problems until I come to the line...

python manage.py satchmo_copy_static

...where I get...

Unknown command: satchmo_copy_static

...what is going wrong?

Also, when I load python I can "import django" and "import satchmo" but not "import satchmo_store" as reading on your next article you have a "satchmo_store_ reference and hence I thought I would see if I could import it in python to check, but get the error "ImportError: No module named satchmo_store".

Any help or feedback is greatly appreciated, and I look forward to more of guides.

Thanks :)

Hi Babul,
Did you copy the Satchmo settings.py and local_settings.py over to your project? You will get this error if you don't have satchmo in your list of INSTALLED_APPS in your settings.py file.

Regarding your "import satchmo_store" error, I think "import satchmo_store" is used in the SVN trunk version of satchmo and not version 0.8.x, which I am using. I updated the link in my blog post to point to the 0.8.1 satchmo documentation instead of the SVN documentation.

I hope this answered your question.


#2 Sam commented on :

THANK YOU SO MUCH FOR THIS!

I never, ever would have been able to install this system without your guide. Well, maybe.

But it probably would have taken me a week instead of an hour.