Coder Social home page Coder Social logo

djangotut-old's Introduction

djangoTut setup

Setup vagrant box

  • Pick box from Vagrant
  • I chose ubuntu/xenial64
    • create new folder, I called mine djangoTut
    • I added the path to djangoTut as an alias called djangoTut by:
      • nano .bash_profile
      • add the line: `alias djangoTut='cd "/Users/PATH_TO_YOUR_DJANGOTUT_FOLDER"'
    • navigate to new folder in terminal
    • vagrant init ubuntu/xenial64
    • edit vagrant file
      • uncomment # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
      • change ports 80 and 8080 to 8000 as that's what the django development server uses
      • so you now have config.vm.network "forwarded_port", guest: 8000, host: 8000, host_ip: "127.0.0.1
    • vagrant reload to load the new vagrant file
    • vagrant ssh to SSH into your new box

Install Django

  • python3 -m django --version to confirm no django installed (or check version)
  • install database, if not SQLite, but tutorial uses SQLite
  • remove django if you have an out of date version
  • install pip
    • sudo apt-get update --fix-missing (I did this at pip's instruction but assume I should have done it first)
    • sudo apt install python3-pip to install pip
    • pip3 install --upgrade pip to upgrade pip
  • setup virtualenv
    • pip3 install virtualenv to install virtualenv
    • cd /vagrant
    • virtualenv ENV to create a new virtual environment in directory ENV
    • source ENV/bin/activate to activate virtual env
  • pip install Django to install Django
  • python -m django --version to check installed version - I have 1.11.3

Set up Django project

  • django-admin startproject mysite to create django settings, database configuration & file structure
  • check project working
    • cd /vagrant/mysite
    • python manage.py runserver 0.0.0.0:8000 to run lightweight non-production development server - here's why 0.0.0.0.:8000

Create app

  • ctrl-c to exit server
  • cd /vagrant/mysite to get to folder with manage.py
  • python manage.py startapp polls to create polls app starter

Add a view

  • edit polls/views.py to: `from django.http import HttpResponse

def index(request): return HttpResponse("Hello, world. You're at the polls index.")`

  • add new polls/urls.py with content: `from django.conf.urls import url

from . import views

urlpatterns = [ url(r'^$', views.index, name='index'), ]`

  • add url pattern url(r'^polls/', include('polls.urls')), and from django.conf.urls import include to mysite/urls.py

To launch

  • in terminal djangoTut or navigate to the folder with your vm
  • vagrant up
  • vagrant ssh
  • cd /vagrant/mysite
  • source ../ENV/bin/activate
  • python manage.py runserver 0:8000

djangotut-old's People

Contributors

aqueum avatar

Watchers

James Cloos 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.