Getting A Pinax Project Up and Running

First, we will install the Pinax starter project and its packages in your local development environment.

Make and Change Directory

You will need to make a directory, then change directory into it.

$ mkdir <directory-name>
$ cd <directory-name>

Create a Virtual Environment

Use of a virtual environment is recommended for Python projects.

Create a Virtual Environment Using virtualenv

Create and activate the virtualenv.

$ pip install virtualenv
$ virtualenv mysiteenv
$ source mysiteenv/bin/activate

Create a Virtual Environment Using Pipenv and Python 3

Alternatively, you can create and activate the virtualenv by using Pipenv.

$ pipenv --three
$ pipenv shell

Install Pinax CLI

Pinax CLI can be installed using pip.

$ pip install pinax-cli

Pinax Starter Projects List

One Pinax CLI is installed, you can view the list of available Pinax starter project releases by using the pinax projects command. Projects with an official release will have a version number next to their name. Projects without an official release will not.

$ pinax projects

Install Pinax Starter Project

You can specify via the command line which Pinax starter project you want to install, and what name to give your project. Pinax CLI identifies and downloads the correct tagged release of that Pinax starter project.

$ pinax start <starter-project-name> <project-name>

Example

$ pinax start account mysite

This is the equivalent of:

$ pip install Django==2.0
$ django-admin startproject --template=https://github.com/pinax/pinax-starter-projects/zipball/account mysite

--dev Flag

Pinax starter project development versions can also be installed using the --dev flag. Pinax starter projects without an official release will need to be installed this way.

$ pinax projects
$ pinax start --dev <starter-project-name> <project-name>

Location Flag

Optionally, you can use the location flag to specify project location. By using this, the project files will be installed within the current directory, rather than within a directory inside of your current directory.

$ pinax start <starter-project-name> <project-name> --location .

Run Your Project on a Local Server

Next, we will get your project up and running on a local server. Doing so enables you to view a private version of your website in your browser as you make changes.

Pinax does this differently than traditional Django projects.

Traditional Run Server

Traditionally, the runserver command is used to run a Django website on a local server.

$ ./manage.py runserver

npm Static Build Process

Pinax uses npm, a JavaScript package manager, to manage front-end dependencies. It's important to follow the additional npm steps. Otherwise, your project design will not render properly!

First, install npm in your project

$ npm install

Install Your Packages Using requirements.txt

If needed, change directory into the project directory that contains the requirements.txt file, then install your packages.

$ cd mysite
$ pip install -r requirements.txt

Install Your Packages Using Pipenv

Alternatively, install your packages using Pipenv and Pipfile

Migrate and Load Fixtures

The migrate command applies your model information to your database.

$ ./manage.py migrate

The loaddata command loads fixtures data into the database.

$ ./manage.py loaddata sites

Run Server

Use npm to run the server

$ npm run dev

Browse to http://localhost:3000/

package.json

The command npm run dev runs the dev script in the package.json file. This script automatically runs the runserver command, and concurrently runs an additional npm script called watch that prepares static and media files.

  "scripts": {
    ...
    "watch": "npm run clean && npm run copy:images && npm run build:css && concurrently --raw \"npm run watch:lint\" \"npm run watch:js\" \"npm run watch:css\"",
    ...
    "dev": "concurrently --raw \"./manage.py runserver\" \"npm run watch\" \"npm run dev:browser-sync\"",
    ...
  }

Collect Static

Before deployment, run the collectstatic command to collect all of your static files in one place.

$ ./manage.py collectstatic

Permissions

results matching ""

    No results matching ""