Django Project Creation Guide
Step 1: Install Django
Ensure you have Python installed (preferably 3.8+). Then, install Django using pip:
pip install django
Step 2: Create a Django Project
Run the following command to create a new Django project:
django-admin startproject project_name
Example:
django-admin startproject myproject
This will create a directory structure like this:
myproject/
- manage.py
- myproject/
- __init__.py
- settings.py
- urls.py
- asgi.py
- wsgi.py
Step 3: Navigate to the Project Directory
cd myproject
Step 4: Run the Development Server
To check if everything is working, run:
python manage.py runserver
You should see output like:
Starting development server at http://127.0.0.1:8000/
Open a browser and go to http://127.0.0.1:8000/, and you should see the Django welcome page.
Step 5: Create a Django App
Inside your project, create an app to handle specific functionalities:
python manage.py startapp app_name
Example:
python manage.py startapp blog
This creates a folder structure like:
blog/
- migrations/
- __init__.py
- admin.py
- apps.py
- models.py
- tests.py
- views.py
Step 6: Register the App in settings.py
In myproject/settings.py, add 'blog' to the INSTALLED_APPS list:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog', # Add your app here
Step 7: Apply Migrations
python manage.py migrate
Step 8: Create a Superuser (For Admin Panel)
python manage.py createsuperuser
Follow the prompts to enter a username, email, and password.
Step 9: Run the Server and Access the Admin Panel
Start the server:
python manage.py runserver
Go to http://127.0.0.1:8000/admin/ and log in with your superuser credentials.
Now, you have a basic Django project set up!