In this lesson, we will walk through the process of creating your first Django project and understanding its structure. Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design.
To create a new Django project, you will use the django-admin command-line utility. This utility helps you to create a new project and manage various aspects of it.
Open your terminal and navigate to the directory where you want to create your project. Run the following command:
django-admin startproject myproject
Replace myproject with your desired project name. This command creates a new directory named myproject with the following structure:
myproject/
manage.py
myproject/
__init__.py
settings.py
urls.py
wsgi.py
__init__.py: An empty file that tells Python to treat the directory as a package.Now that you have created your project, you can run the development server to see if everything is set up correctly. Navigate into your project directory and run:
cd myproject
python manage.py runserver
You should see output indicating that the server is running. Open your web browser and go to http://127.0.0.1:8000/. You should see the Django welcome page!
Ensure that Django is installed: If you encounter an error like
django-admin: command not found, make sure Django is installed in your environment.Running the server from the wrong directory: Always run
manage.pyfrom the project's root directory.
In this lesson, you learned how to create a new Django project and explored its structure. You also learned how to run the development server to check your setup. This foundational knowledge is crucial as you continue to build your Django applications.
myfirstsite. Run the development server and check if the welcome page appears.settings.py file to change the DEBUG setting to False. What happens when you try to run the server?python manage.py startapp blog. What files are created in the blog directory?django-admin startproject.manage.py, settings.py, and urls.py.