Symons
Passionate developer with 3 years of building web apps with python Django. Symons is a graduate from Maseno University with Bsc Computer Science degree. He is mostly happy when his students make strides

Django Project Structure | CHAPTER 2: Creating Our Project

Here we are going to create a project and try to understand the Django Project Structure, at the end I have a bit of bonus advice for you check it out. Ensure you have done the following:

Let us get to work

Note: if you have understood project creation you can use this script to automate the process

Fire up your terminal and cd into project directory another way is open the folder you created venv and open terminal, list to see the content of that folder. I only have venv as you can see below:

symons@symons-macbookair:~$ cd STICKETING
symons@symons-macbookair:~/STICKETING$ ls
venv

Next, we need to activate our venv with source venv/bin/activate on windows venv\Scripts\activate

symons@symons-macbookair:~/STICKETING$ source venv/bin/activate
(venv) symons@symons-macbookair:~/STICKETING$ 

Time to create a project using:  django-admin startproject Sticketing . don’t forget the dot at the end, it ensures the project is created in the current directory. it is not necessary though. on windows use django-admin.exe startproject Sticketing .

(venv) symons@symons-macbookair:~/STICKETING$ django-admin startproject Sticketing .
(venv) symons@symons-macbookair:~/STICKETING$

We have created Django project. You should see manage.py and another folder named Sticketing in our current folder STICKETING

django project folfer

Managepy helps us run some commands like staring server or creating a superuser, you will be able to see in a few minutes but you can read about it online

Now open Sticketing folder

django project structure

__init__.py will mark this folder as containing python packages. It makes imports easy for example if urls.py contain a function b() we can import it in another file as

from urls import b()

settings.py Contains project configurations eg allowed hosts, databases to be used etc.

urls.py we will talk about next.

wsgi.py:  It’s used both by Django’s development server and in production WSGI deployments. We will use it when we are deploying

Let’s see if our project works:

I hope up to now you understand the Django Project Structure.

Run the development server:

Run python manage.py runserver

(venv) symons@symons-macbookair:~/STICKETING$ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 17 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.

February 17, 2020 - 20:32:51
Django version 2.2.10, using settings 'Sticketing.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Our server is running!!!! Congrats!!

visit http://127.0.0.1:8000/  To see

first django project

And that is the most important things you need to know about the Django Project Structure.

Done for now. Please take two minutes to read the bellow insights

As you will be following along or learning to code you will always find challenges here are some challenges I personally faced and how I got over them.

Errors and bugs:

Along the way, you get a lot of errors and things won’t work as you expect, if you are weak you will quickly give up and move to another language or framework.

If you get these errors try and solve them,

  • First, try and understand what the error means, if you don’t understand look for familiar words in the error statement this will give you a clue.
  • Then try and fix it
  • If you can’t fix it yourself google search, then find relevant results I normally prefer from StackOverflow
  • If you still can’t find a solution you can ask your question in StackOverflow, ask friends or your mentor. Someone who can help you physically or check your files from Github or via screen sharing

Errors have actually helped me learn more than anything else.

 

Things not making sense:

 

It is almost obvious that when you learn something for the first time most concepts won’t make sense, it is normal, just keep doing it again and again and you’ll crack it. A time I leave something that I can’t understand at that time, proceed and then go back to it the next day and I loop the process.

You don’t have to learn everything and have them at your fingertips, you can always refer to them, it is only important you know that they exist and what they do.

Feeling like giving up:

You will probably feel like giving up and loose the morale you started with. This normally happens when you are about to get things right you don’t just realize. Just ensure hold on, keep the vibe.

I used to keep my GitHub activity green, this encouraged me to code every day since I didn’t want my activity to have white gaps. You can do the same or make a calendar and mark every day you code so if you don’t mark a day you should feel bad. Think of what you could make if learning Django becomes successful.

the moment you start feeling like giving up just know you are about to make it to the other side

 

I’ll update these challenges or do another post.

close

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *