How to setup Django project and App

Firstly, install python on your machine and do make the virtual environment, just follow the link if you’re not aware of virtualenv.

Follow the pip command below and install Django, make sure you should be working the directory, with this command, it make a folder with the given project name and it has some files.

Django folder structure: the main two files are settings.py and urls.py

In setting.py, here we declare what applications we are using in the installed list in this file, we can configure middleware for our projects, templates, static and media files.

with urls.py we attach applications with the main project and with that particular app, here command for making Django project.

Be in that folder and open cmd and run python manage.py runserver, it run our project in default browser with 8000 localhost

This command creates a new folder with firstapp, first you need to configure a new app to Django project for that you need to add ‘firstapp’ in the installed list of main project settings.py file. The new application comes with files like views.py(where we declare our functionality), models.py(here we make our database class’s) and we need to make new files as urls.py in this folder for attaching it to the main project urls.py.

Make sure, you are in the main project folder while running the server, now you can create templates and static folders for handling the HTML files and javascript, images, CSS files respectively.

Django comes with few tables like users, authentication, groups. After adding a new class in the models.py file you need to run the above command and run the below command after that.

You can see the default tables in the Django admin panel, first create superuser by this command below

Put username and password and then run python manage.py runserver and go to browser and put /admin after your 8000 localhost URL

Their many ways to write the code in Django views like function-based or class-based and we can use Django ORM(Object Relation Mapping) rather than MySQL queries. With all information, you need to refer to a youtube tutorial or documentation for running the whole project with applications.

Please do it practically, if you don't, simple you won't learn.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store