Skip to content

Instantly share code, notes, and snippets.

@Sierra-034
Last active August 31, 2023 02:39
Show Gist options
  • Save Sierra-034/914486c24b544e0f8112bfc446801aa9 to your computer and use it in GitHub Desktop.
Save Sierra-034/914486c24b544e0f8112bfc446801aa9 to your computer and use it in GitHub Desktop.
Django getting started

Manual to get started with django

First we have to create a directory which will hold you main code. Inside that folder you will have to create your virtual environment. Once your venv is created you will have to create django project with the following command: django-admin startproject project-name

Project folder structure

asgi.py and wsgi.py are config files for deployment.

settings.py

Lorem ipsum dolor sitamet

How to start the project

Once you have your project structure, you can run your server with: python manage.py runserver. You can also modify the project settings where you can establish some project configuration such as DEBUG, ALLOWED_HOST, INSTALLED_APPS (where you can define which apps are going to be availables inside the project manager UI), you can also define a database (sqlite3 default as ENGINE value)

How to create a django app (overview)

In order to create a django app you need to write the following command: python manage.py startapp app-name Once you have your application you can add it to the INSTALLED_APPS list inside the settings.py file.

In order for our models inside our newly app to be available inside UI manager you have to register them down inside the admin.py file inside the app you are working on. You accomplish this by entering the following code.

from .models import <ModelClassTablesList>

admin.site.register(TableClassModelName)

Once you have your tables difined inside models.py you need to create your migrations with: python manage.py makemigrations. Then you have to migrate them with: python manage.py migrate

Admin site

First you have to create a superuser account. You can do this by running the next command: python manage.py createsuperuser you will be asked for your username as well as email and password. Once your superuser created, you can enter the admin site by appending /admin to the base url. You will find a login page wher you have to enteryou super user credentials.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment