Giter Site home page Giter Site logo

sfbaywildlifetracker_sample's Introduction

Kickstart Coding Logo

Kickstart Coding: Django Project Starter

This is an example start project for Kickstart Coding Django projects.

It provides a solid foundation for building a Django project that's ready to launch to Heroku or similar web-hosting service.

About

Features

  • Bootstrap 4: It's all set-up with Bootstrap 4 templates, a few example pages, and django-bootstrap4 for easily bootstrap-based forms

  • Accounts:

    • Log-in and sign-up pages
    • Custom user class
    • User profile page and user editing page
  • Heroku support: It's one git push away from publishing to the world

  • Pipenv: It's set-up to use Pipfile

  • Code standards: This was created to be a happy medium between the default django-admin starting template and heavier weight scaffolding such as Audrey / Daniel Greenfield's Django Cookiecutter, which might be better for larger projects

  • Easy development:

    • Separate local and production settings
    • Use Sqlite locally and postgres in production
    • While for bigger projects production / dev parity is vitally important, this is great for getting started with smaller projects
  • Misc nice stuff:

    • django-debug-toolbar -- great debugging tool
    • Error pages

Who is this for

  • This is for new Python/Django programmers, including coding class students who want a solid start for a Django project that uses SQLite when developing locally, and is ready to deploy Heroku provisioned Postgres database.

  • The documentation assumes you already have fundamental Python, Django, Bash and Heroku knowledge. If you are new to Heroku, read our Heroku Getting Started guide. If you are new to Postgres, read our Postgres Getting Started guide .

  • The documentation does not explicitly support Windows. It assumes you use either macOS or a GNU/Linux distribution such as Ubuntu. That said, it might work.

This was original created for Kickstart Coding, the affordable, inclusive, and intensive coding course teaching cutting-edge Python / Django and JavaScript / React web development in Oakland, CA. Learn more and enroll here.

Development

  • Prereq: You have Pipenv installed. You have Django admin installed globally (macOS type pip3 install django, Ubuntu GNU/Linux, type sudo pip3 install django)

Running locally

  1. Assuming mycoolproject is the name of your project, you should start a new project using this template as follows:
django-admin startproject --template=https://github.com/kickstartcoding/django-kcproject-starter/archive/master.zip mycoolproject
  1. Go into the newly created project, and use pipenv to get your virtualenv setup:
cd mycoolproject
pipenv shell
pipenv install --dev

Note: It's probably okay if you get errors while installing psycopg2 or gunicorn. These are not needed for development, and are likely to install fine when they are needed, e.g. on Heroku.

  1. This starter project does not include migrations. Make migrations as such:
python manage.py makemigrations accounts
  1. Run the migrations to actually create the SQLite database:
python manage.py migrate
  1. Get the server running:
python manage.py runserver

Setting up with GitHub repo

  1. Create a new repo on GitHub, and BE SURE TO NOT check "initialize with README.md" or .gitignore or anything. You want to make a truly blank repo for these steps to work without a hiccup. Just fill in the name and description, and nothing else.

  2. Now, initialize and push the code we have by running this in the command-line:

ls # Ensure you are "next to" the manage.py, etc
git init # Initalize this
git add -A # Add all your files
git commit -m "first" # Make a commit
  1. Finally, link up your local repository with the git one, and push. Follow the instructions provided on the github.com page. They will look a little like this, except instead of janeqhacker/mycoolproject it will be whatever your username is and your repo name is:
git remote add origin [email protected]:janeqhacker/mycoolproject.git
git push -u origin master

File structure

Directory structure description below:

[name_of_project]/
    - config/
        - base.py          # Stores most settings
        - local.py         # Stores settings only for local dev
        - production.py    # Stores settings only used by production (e.g. Heroku)
    - urls.py              # Global urls.py, in turn includes urls.py in apps

- apps/                    # A directory to store all our custom apps
    - accounts/            # An example custom app that includes sign-up and log-in
        - models.py        # Customized user class is here
        - urls.py          # URLs for sign-up and log-in pages
        - views.py         # Views for sign-up and log-in pages
        - forms.py         # Form for editing user profile, sign-up
        - templates/       # Templates for user profile stuff
    - core/                # An example custom app that has some static pages
        - static/          # Static files
        - templates/       # Core templates, including base templates
        - etc
- manage.py                # Entry point
- Pipfile                  # Development requirements

Production

Provisioning on Heroku

  1. Creating a new Heroku app & Postgres Database (only need to do this once per Heroku):
heroku create # Create a Heroku app (only run this if you haven't already)
heroku addons:create heroku-postgresql:hobby-dev
  1. Optional: Confirm that the database is working by connecting to it with the command-line client (Ctrl+D to exit):
heroku pg:psql
  1. Push to Heroku
git push heroku master
  1. Run the migrations on the remote Postgres database. That can be done as follows:
heroku run python manage.py migrate
  1. Your site should work! View it in your browser.

  2. You'll also want to add a SECRET_KEY to Heroku to make your site secure:

heroku config:set SECRET_KEY=randomly hit keys

NOTE: Where it says "randomly hit keys", do just that! Just type a really long random series of letters and numbers. You'll never have to remember it again.


Going further

Mailgun-powered email

Add env variables to Heroku as such: * MAILGUN_API_KEY * MAILGUN_DOMAIN

Then, add the following to your production.py:

# Anymail (Mailgun)
# ------------------------------------------------------------------------------
# https://anymail.readthedocs.io/en/stable/installation/#installing-anymail
INSTALLED_APPS += ['anymail']  # noqa F405
EMAIL_BACKEND = 'anymail.backends.mailgun.EmailBackend'
# https://anymail.readthedocs.io/en/stable/installation/#anymail-settings-reference
ANYMAIL = {
    'MAILGUN_API_KEY': env('MAILGUN_API_KEY'),
    'MAILGUN_SENDER_DOMAIN': env('MAILGUN_DOMAIN')
}

AWS S3

AWS S3 is great for handling uploaded files. Typically, this is exactly what you need: AWS supports as many and as large of files that your users might want to upload.

sfbaywildlifetracker_sample's People

Contributors

ishinan avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.