The Django Project
Basic Startup Tutorial1. Install Database of choice (e.g. MySQL, PostGresSQL) 2. Install Django: pip install Django Writing your first Django app, part 1Tutorial can be found here: Throughout this tutorial, we’ll walk you through the creation of a basic poll application. It’ll consist of two parts:
Create a ProjectIf this is your first time using Django, you’ll have to take care of some initial setup. Namely, you’ll need to auto-generate some code that establishes a Django project – a collection of settings for an instance of Django, including database configuration, Django-specific options and application-specific settings. From the command line, cd into a directory where you’d like to store your code, then run the following command: django-admin startproject mysite This will create a mysite directory in your current directory. Let’s look at what startproject created: mysite/ manage.py mysite/ __init__.py settings.py urls.py wsgi.pyThese files are:
The Development ServerLet’s verify your Django project works. Change into the outer mysite directory, if you haven’t already, and run the following commands: py manage.py runserver Some messages appear including:
Now’s a good time to note: don’t use this server in anything resembling a production environment. It’s intended only for use while developing. (We’re in the business of making Web frameworks, not Web servers.) Now that the server’s running, visit http://127.0.0.1:8000/ with your Web browser. You’ll see a “Congratulations!” page, with a rocket taking off. It worked! Changing the port By default, the runserver command starts the development server on the internal IP at port 8000. If you want to change the server’s port, pass it as a command-line argument. For instance, this command starts the server on port 8080: / ...\> py manage.py runserver 8080 |
