Django create project
Create a Django project
To create a new Django project, open up a terminal and navigate to the directory where you want to store your project. Then, run the following command
django-admin startproject myproject
This will create a new directory called “myproject” with the following file structure.
myproject/ ├── manage.py └── myproject/ ├── __init__.py ├── asgi.py ├── settings.py ├── urls.py └── wsgi.py
Now Navigate to the root directory of your Django project. You can run this by the following command
Run the Django project
At this stage, you have successfully created a Django project and now it’s time to run the server to see what it looks like’s in the browser. You can run the server by the following command:
python manage.py runserver
Watching for file changes with StatReloader Performing system checks... System check identified no issues (0 silenced). You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. Run 'python manage.py migrate' to apply them. January 08, 2023 - 08:05:53 Django version 4.1.5, using settings 'myproject.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK.
You can view this on your browser by visiting http://127.0.0.1:8000/ this link.
Django admin page
Next, it’s time to create an admin username and password for our website. For this, you can run the following command to create a super admin user.
Note: Before doing this we want to migrate all files to the database you can do it by running the command python manage.py migrations and then python manage.py migrate this will migrate all files to the database
After migration now it’s we can create a superuser for our project. You can do this by running the following command
python manage.py createsuperuser
This will ask for a username. You can enter blank to use your windows or any other OS that you are using the username as your site admin username
Username (leave blank to use 'user'):
After entering the username next it will ask for an email address. You can time desired email address here
After typing the email address next it will ask for a password. After successfully creating and confirming the password now you are ready to log in as an admin user on your website.
You can browse to the following URL to access the admin page: http://127.0.0.1:8000/admin.
In conclusion, Django is a powerful web framework that enables the rapid development of secure and maintainable websites. In this tutorial, we walked through the process of creating a simple project with Django,
- pybase64 encode and decode Messages using Python - June 6, 2023
- Different Data Types in Dart - June 6, 2023
- What is flutter and dart and the difference - June 4, 2023