New to Python? or already dancing some tango with it and you feel it’s time to dabble into some framework magic for web?
In this tutorial, I will be showing you how to get your first Django website up and running. Before we start, we need to have Python downloaded and installed on our System, to download and install python, click here .
Note: You need to already have a basic understanding of python, also I’ll be running this tutorial on a Linux based system, so most commands would follow suite the linux way. But there will be little or no difference on most.
To exit, type in ctrl + z.
Next thing we need to do, is set up our virtual environment, a virtual environment helps you run several versions of python/django right on your machine (e.g you could have two different python/django projects running on different versions, to avoid them clashing and to give you room to run them both without errors, the virtual environment comes to your rescue. One virtual environment = one python/django version).It’s strongly advised to always use a virtual environment.
Note: env_name should be replaced with the preferred name of your environment. (I like to name my environments with the django version installed in it for easier recognition).
Using ==1.8 only gives a direction to django about the particular version you want to install, in this case version 1.8. To just go ahead and download the latest version, input pip install django .
Note: project_name = name of your project . In this case, we’ll work with mask_off as our project name.
1) the init.py helps python treat the directories as containing packages; so as to prevent directories with a common name, from unintentionally hiding valid modules that occur later (deeper) on the module search path.In most cases, it’s usually an empty file.
2) The settings.py file contains all settings your project requires, as we progress, we’ll visit this file often.
3) The WSGI (Web Server Gateway Interface) acts as the interface our web server uses to interact with our web application. Read more about it here.
Migrations helps us make changes to our database schema without losing any data, each time we create a new model or make changes to a current one and run migrations, it helps update our database tables with the schemas without having to go through all the stress of dragging and recreating the database ourselves.
Yaah! our very own webpage.
Now we have our server running and a ‘webpage’ , but django takes pleasure in reminding us we still have a lot of work to do before we can proudly call this a webpage.
The second part of this tutorial would contain; Creating a new app in our project, working with Urls, Templates, Creating views and Linking pages. For now, take out more time to go through the steps again and again to become more familiar with them. Only practice makes perfect!
Thanks for the tutorial, Ada! I'll definitely try it this weekend.
There seems to be a lost link here.
Its great, well explained. Looking forward for next tutorial on creating a new app.
I have never worked in Django, but this tutorial and you are my go-to if I find myself in that world.
Hi Jeff, great observation, would def. follow that method in my next articles. Thanks!