class-3.0 is one large Django project split up into multiple parts.
First, we make the distinction between backends and frontends. Then,
- Within backends are multiple Django apps (see here for distinction between "app" and "project")
- Within frontends are multiple React apps corresponding to the the backend apps.
- Clone this repo (or your fork of it). We'll refer to the directory you cloned it to as
class/. - Setup the Python/Django tools and environment
- Ensure you have
Python 3(and notPython 2).- Many systems come with both, try
python --versionorpython3 --version(and alsopip --versionandpip3 --version) until you find the right one. We'll assumepythonandpiprefer to thePython 3versions for the rest of the setup. - Otherwise head to https://www.python.org/downloads/release/latest or your system's package manager to install the latest.
- Many systems come with both, try
- Install
virtualenv.- Virtualenv is a python utility that allows us to isolate and keep track of dependencies for separate python projects
- Run
pip install virtualenv. If you don't have permissions, try running it in an Administrator terminal or prefixing withsudo. Alternatively runpip install --user virtualenv
- Create a new Virtualenv, and install the Python dependencies
- cd to
class/ - execute
virtualenv venvto make a new Virtualenv called venv - run
source venv/bin/activate(orvenv\Scripts\activateon Windows) to activate/enter into the Virtualenv - then
pip install -r requirements.txt; this will install dependencies into the venv
- cd to
- Ensure you have
- Setup the JavaScript/Webpack/React tools and environment
- Ensure you have Node and NPM
- You can check with
node --version(or potentiallynodejs --version) andnpm --version. - Otherwise head to https://nodejs.org/en/ or your system's package manager to install the latest.
- You can check with
- Install the JavaScript dependencies and toolchain
- cd to
class/frontends/ - run
npm install; this will install dependencies into a directory callednode_modules
- cd to
- Ensure you have Node and NPM
- Remember to
git pull(orgit fetchfollowed by merge/rebase) the latest changes! - Running the frontend development toolchain
- Remember
- if any dependency problems arise, cd to
class/frontends, and re-runnpm installas dependencies may have changed
- if any dependency problems arise, cd to
- cd to
class/frontends - run
npm run devto run a continuously-building development server that will auto-rebuild upon file changes - or
npm run buildto build a highly-optimized version once
- Remember
- Running the backend
- Remember
- activate the venv (once per terminal) before executing anything related to Python
- build the frontend at least once (so that the server will have something to serve!)
- if any dependency problems arise, activate the venv, cd to
class/, and re-runpip install -r requirements.txtas dependencies may have changed
- cd to
class/backends - run
python manage.py runserverto run the server and make it accessible (via a browser) athttp://127.0.0.1:8000
- Remember
- Make sure everything is running as per the section above
- Make yourself an admin account
- cd to
class/backends/ - run
python manage.py createsuperuser, filling in an email and password when prompted
- cd to
- Go to
http://127.0.0.1:8000/admin/and log in - At the admin page, make some initial users, classrooms, and students (in that order)
- You can now login with the newly created users at
http://127.0.0.1:8000/api-auth/login/, allowing you to navigate the various api calls via the REST framework
An app called foobar would have various components like
- A line
'foobar.Foobar'in theINSTALLED_APPSlist ofclass/backends/class/settings.py - An entry
url(r'^foobar/', include('foobar.urls'))inclass/backends/class/urls.py - The Django app directory
class/backends/foobar, and inside__init__.pycontaining aclass Foobar(AppConfig)definitionadmin.pycontaining Django admin panel registrationmodels.pycontaining the database models used by the appurls.pycontaining routes used by the appview.pycontaining most of the backend code for the app*.py(other supporting files)- potentially a
templates/foobardirectory containing custom templates (remember that thecoreapp has shared useful templates that apps should try to use as much as possible)
- A line
foobar: './foobar/index.js'in theentrydefinition inclass/frontends/webpack.config.js - The React app directory
class/frontends/foobar, and insideindex.jscontaining routes, CSS imports, and the base component of the app.*.jsand*.css(other supporting files and components)
Remember that apps should use as much stuff from the core app as possible to promote interoperability and reduce redundancy.
For instance, the core app provides a basic React-loading index.html template, obviating the need for most apps to provide their own templates.