Start a Django Project From Scratch — (1)
Django is a python framework that helps perfectionists with deadlines to make a server quickly. Literally, using Django is super easy so that anyone who has no idea of backed development can easily learn with the well-organized official document. I’ll explain the whole process that you’ll have to do to develop your website in either server-side or client-side.
In this article, I’ll cover the basics of Django :
- Install Django and set up a Django project
- Start a Django app
- Run server
In a virtual environment you already set, You will install Django with pip, which is the package installer for Python. Like all python libraries, all you need to do is to code one line :
Once it installed, create a directory where you manage your Django projects. Walking into the directory, set up your first Django project with
Then, you can see that a new project folder is created in your current directory, which has the same name as you typed in your code above. The project contains one folder and one python file that was named
manage.py is a command-line utility that lets you interact with your Django project in many ways. In other words, most of the commands regarding your projects are handled by
manage.py . Running its server or migrating your models to DB is also up to it. The folder whose name is same as your project is just a container for your project so that you can rename it to anything you like. The project container has several python files and we’ll take a close look at the files later on.
Now that your project is ready, it is time to start work. To do something with Django, you will need to make an application, which consists of a Python package that follows a certain convention. Just make sure that you are in the same directory as
manage.py and type this command :
That will create a directory blog, which is laid out like this :
Even though you have never written a code so far, you can run the server of this environment. Surprisingly, it works and will show you an amazing website with a rocket launched. Once you type the
runserver command, it starts the development server on the IP at port 8000 by default. If you want to change the server’s port, pass it as a command-line argument. More information for changing the port can be found in the runserver reference.
From now on, we will do various kinds of things based on the website. We could make our own page and establish CRUD system to the default
sqlite DB. For that, we need to understand how Django reacts when a client gives a request. In the next article, we will cover its unique design pattern MVT and its components in your projects. Thanks for reading this article and I hope you guys stay tuned with me.