Django
Django Project Setup
Create a Django project
Django Project Setup
Creating a Django project is straightforward. Django provides a command-line utility that automates the creation of project directories and files.
Create a Django Project
Use the django-admin command to create a new project:
django-admin startproject myproject
This creates a directory called myproject with the following structure:
myproject/
manage.py
myproject/
__init__.py
settings.py
urls.py
asgi.py
wsgi.py
Project Structure
- manage.py: A command-line utility for interacting with your Django project
- settings.py: Configuration for your Django project
- urls.py: URL declarations for your Django project
- wsgi.py: Entry point for WSGI-compatible web servers
- asgi.py: Entry point for ASGI-compatible web servers
Run Development Server
Navigate to your project directory and run the development server:
cd myproject
python manage.py runserver
You should see output like:
Starting development server at http://127.0.0.1:8000/
Access Your Project
Open your browser and go to http://127.0.0.1:8000/. You should see the Django welcome page.
Run Migrations
Before you can use the admin interface, you need to run migrations:
python manage.py migrate
Create Superuser
To access the admin interface, create a superuser:
python manage.py createsuperuser