Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,143,358 members, 7,780,973 topics. Date: Friday, 29 March 2024 at 06:41 AM

Learn How To Create Websites With Python(Django Web Framework) - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Learn How To Create Websites With Python(Django Web Framework) (5708 Views)

Python With Django Web Development Training using Real World Projects! / Why Django Is The Best Web Framework For Your Project / Let's Build A Simple Blog With Python(django) (2) (3) (4)

(1) (2) (3) (4) (Reply) (Go Down)

Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 3:09pm On Mar 27, 2020
Now that we are at home.. Instead of whiling away time.. We could pick up a skill. So I am offering to show us how we can create websites using Python programming language through the Django web framework..

Prerequisites:
1. Know fundamentals of Python programming language.
2. Knowledge of HTML, CSS, JS(not really needed).
3. Your dedication, patience, interest and support..
4. A little knowledge of how the web works(I may explain this tho)

Oh! Yes, your laptops or PC's are needed to follow along.

If I can get at least ten interested folks I will start, please do indicate if interested, I am all out for you guys..

P:S
We will create a:
1. Poll website
2. Nairaland clone
3. Chat website
4. Facebook clone

1 Like

Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 3:33pm On Mar 27, 2020
Okay let me give an introduction to Django.

Django is a free and open source web application framework, written in Python.

A web framework helps you to develop websites faster and easier. Frameworks exist to save you from having to reinvent the wheel. So instead of spending weeks on creating a website, Django reduces it to days..

Django is:

1.Ridiculously fast.

2.Reassuringly secure.

3.Exceedingly scalable(Can grow and handle increasing load)

1 Like

Re: Learn How To Create Websites With Python(Django Web Framework) by Kyrx(m): 3:36pm On Mar 27, 2020
I'm seated!
Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 3:41pm On Mar 27, 2020
Kyrx:
I'm seated!

You are welcome man.
Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 3:46pm On Mar 27, 2020
POST 1
Okay let's get our laptops or PC's ready.
To be able to use django we need to install Python software, being a Python Web framework, Django requires Python.

So get the latest Python software from https://www.python.org/downloads/

P:S
After downloading the installer, you should run it (double-click on it) and follow the instructions there.

One thing to watch out for: During the installation, you will notice a window marked "Setup". Make sure you tick the "Add Python to PATH" or 'Add Python to your environment variables" checkbox and click on "Install Now",
Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 3:56pm On Mar 27, 2020
I would take a pause now. I need feedback please. Let me wait for others. undecided
Re: Learn How To Create Websites With Python(Django Web Framework) by Lorazepam(f): 4:51pm On Mar 27, 2020
Carry on sir smiley

1 Like

Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 7:41pm On Mar 27, 2020
At least eight more people needed..
Two people have already shown interest.
Re: Learn How To Create Websites With Python(Django Web Framework) by deekseen(m): 8:24pm On Mar 27, 2020
Topics/lectures like this are evergreen.

People will find this days, weeks, months or years later and will be grateful to you for it.

I may not comment on this again, but like a lot of people that will come across this thread, I'll be following every post in the background.

Kudos op. Continue.

1 Like

Re: Learn How To Create Websites With Python(Django Web Framework) by MichelleObama: 8:31pm On Mar 27, 2020
Keenly following, currently working on python and Django video tutorial by Mosh

2 Likes

Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 8:57pm On Mar 27, 2020
POST 2
Make sure you have installed on your system the latest Python version to avoid any compatibility issue.

To check whether you have installed Python correctly open up your Command Prompt and type in
py --version
This should return the python version you have installed.. Meaning python installed successfully.

1 Like

Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 9:18pm On Mar 27, 2020
POST 3
Now python is installed on your device. Since a person may have different web projects on his system, it is advisable to have a version control mechanism, this helps to exclude a project to its packages, therefore preventing other projects from clashing, so its like each project is independent from others...

Python calls this virtualenv meaning virtual environment.
In your command prompt type
pip install virtualenv make sure you are connected to the internet.
This will install the virtualenv package.

Now let's create an isolated environment using the virtualenv we have installed. In your command prompt type in virtualenv env, this will create a env directory.

After creating your virtual environment, we need to activate it, in your command prompt type in
env\Scripts\activate

Kudos.You have successfully created a virtual environment. You will get to understand the need as we advance.

1 Like

Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 9:27pm On Mar 27, 2020
N:B
Hey people. If you have any questions or you encounter any error feel free to ask me..

1 Like

Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 9:33pm On Mar 27, 2020
POST 4
We have installed Python and created a virtual environment, moving on..

Let us install Django
In your command prompt type in:
pip install Django
This will install Django in your virtual environment..

N:B If you closed your command prompt you need to activate your virtual environment again using env\Scripts\activate
Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 9:46pm On Mar 27, 2020
POST 5

We are going to create our first project. What does project mean? In simple terms take a website like Facebook it's a project made up of many functionalities which in Django we call app. Basically the functionalities are called apps, while the entirety is the project. You get??

Our first project will be a polling website- where users vote for a preferred choice like they do on Twitter or FB.

Something like the image below..

1 Like

Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 10:39pm On Mar 27, 2020
POST 6

Let's create an initial project file structure
Run the following in your command prompt:
django-admin startproject mysite
This will create a Django project with the name mysite.
If you go into your file explorer you would see a directory
called mysite which will contain the following:

mysite/ - outer directory
manage.py - allows us to interact with our project in many ways
mysite/ - inner directory
__init__.py - An empty file that tells Python to treat the
mysite directory as a Python module.
asgi.py
settings.py - as the name implies
urls.py - holds your URL patterns
wsgi.py

You know I said Django helps save time, so Django comes with
all these originally, we don't need to start recreating them
again. So don't delete anything.

Now let's check if what we have done so far works..
Run the following in your command prompt:
cd mysite
py manage.py runserver

Django comes with a lightweight server, so you don't need to worry
about setting up one until you want to go live(internet).

Go to your browser and visit http://127.0.0.1:8000/
You'll see a congratulations page, something like the image below.

Phew.. Hard work, things are about to get more interesting..

1 Like

Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 10:53pm On Mar 27, 2020
Okay I have to go and rest.
We will def continue tomorrow.
I just want to know that I am not alone, drop your feedback, questions and problems.
I am here for you.


Good night

1 Like

Re: Learn How To Create Websites With Python(Django Web Framework) by KevMitnick: 11:46pm On Mar 27, 2020
Nice job bro. Following

1 Like

Re: Learn How To Create Websites With Python(Django Web Framework) by deekseen(m): 12:00am On Mar 28, 2020
Nice one
ColeDrain:
POST 6

Let's create an initial project file structure
Run the following in your command prompt:
django-admin startproject mysite
This will create a Django project with the name mysite.
If you go into your file explorer you would see a directory
called mysite which will contain the following:

mysite/ - outer directory
manage.py - allows us to interact with our project in many ways
mysite/ - inner directory
__init__.py - An empty file that tells Python to treat the
mysite directory as a Python module.
asgi.py
settings.py - as the name implies
urls.py - holds your URL patterns
wsgi.py

You know I said Django helps save time, so Django comes with
all these originally, we don't need to start recreating them
again. So don't delete anything.

Now let's check if what we have done so far works..
Run the following in your command prompt:
cd mysite
py manage.py runserver

Django comes with a lightweight server, so you don't need to worry
about setting up one until you want to go live(internet).

Go to your browser and visit http://127.0.0.1:8000/
You'll see a congratulations page, something like the image below.

Phew.. Hard work, things are about to get more interesting..



2 Likes

Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 8:17am On Mar 28, 2020
POST 7


HOW THE WEB WORKS as I promised

You are browsing with your phone, you want to go to Nairaland website, you type in nairaland.com, you press enter- immediately you do this you are making a request to a web server(it holds all the code of a website) asking for nairaland home page (nairaland is just a bunch of code, basically).

The server takes the url(nairaland.com) and tries to match it with a set of urlpatterns(it's just trying to know what the user wants)
Once it finds a match, it passes the request to a function(which is called view in django), the view then generates a response which is sent to the user's browser.

To make it more simplified- Imagine a postman with letters(take the letters as urls), he checks the address of each house to see if it matches with what he has, once he finds a match he drops the letter there. You get??

I hope you have an idea of how the web works..

2 Likes

Re: Learn How To Create Websites With Python(Django Web Framework) by MichelleObama: 8:37am On Mar 28, 2020
Good morning ColeDrain, I have been waiting you, being refreshing since

1 Like

Re: Learn How To Create Websites With Python(Django Web Framework) by Meel: 8:53am On Mar 28, 2020
very educating thread, thumbs up op

1 Like

Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 8:53am On Mar 28, 2020
POST 8

Back to course, our server is still running from the command prompt, to stop it type ctrl + c.

If you closed your CMD prompt(make sure you activate your virtual environment and go to the directory of mysite as shown below)

(env) C:\Users\AYOMIDE\mysite>

Now in POST 6 we created a project file structure, now let's create an app file structure(I've explained the diff btw app and project)
Run this in your CMD:
py manage.py startapp polls
That will create an app named 'polls' basically a folder on your computer with various files in them as shown below(open your file explorer you should see it)
polls/
__init__.py
admin.py
apps.py
migrations/
__init__.py
models.py
tests.py
views.py

Okay now you need to open your text editors(notepad++, sublime text, vs code, atom etc), I will advise to download sublime text, abeg no use notepad.
Open up the mysite folder in your sublime text, then open the views.py file in the polls directory and type in the following python code.

from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.

def index(request):
return HttpResponse("Hello World. You are doing well"wink


pls put a bracket inplace of that emoji(nairaland ish)..

You should have something like the picture below

If you are lost tell me

2 Likes

Re: Learn How To Create Websites With Python(Django Web Framework) by MichelleObama: 10:30am On Mar 28, 2020
I am having this error, what could cause it

(env) C:\Users\Owner>python manage.py startapp polls
python: can't open file 'manage.py': [Errno 2] No such file or directory
Re: Learn How To Create Websites With Python(Django Web Framework) by thug: 10:31am On Mar 28, 2020
I successfully installed Django last nite but now am having difficulties in activating and creating new app. Can you kindly put more light.
I sincerely appreciate the work you are doing so far

1 Like

Re: Learn How To Create Websites With Python(Django Web Framework) by nelxxy(m): 11:25am On Mar 28, 2020
MichelleObama:
I am having this error, what could cause it

(env) C:\Users\Owner>python manage.py startapp polls
python: can't open file 'manage.py': [Errno 2] No such file or directory
you are not in your project folder. use cd to navigate to your project folder(i.e to where manage.py is located)
Re: Learn How To Create Websites With Python(Django Web Framework) by nelxxy(m): 11:33am On Mar 28, 2020
thug:
I successfully installed Django last nite but now am having difficulties in activating and creating new app. Can you kindly put more light.
I sincerely appreciate the work you are doing so far

follow this instruction

ColeDrain:
POST 6

Let's create an initial project file structure
Run the following in your command prompt:
django-admin startproject mysite
This will create a Django project with the name mysite.
If you go into your file explorer you would see a directory
called mysite which will contain the following:

mysite/ - outer directory
manage.py - allows us to interact with our project in many ways
mysite/ - inner directory
__init__.py - An empty file that tells Python to treat the
mysite directory as a Python module.
asgi.py
settings.py - as the name implies
urls.py - holds your URL patterns
wsgi.py

You know I said Django helps save time, so Django comes with
all these originally, we don't need to start recreating them
again. So don't delete anything.

Now let's check if what we have done so far works..
Run the following in your command prompt:
cd mysite
py manage.py runserver

Django comes with a lightweight server, so you don't need to worry
about setting up one until you want to go live(internet).

Go to your browser and visit http://127.0.0.1:8000/
You'll see a congratulations page, something like the image below.

Phew.. Hard work, things are about to get more interesting..



Re: Learn How To Create Websites With Python(Django Web Framework) by MichelleObama: 11:38am On Mar 28, 2020
nelxxy:

you are not in your project folder. use cd to navigate to your project folder(i.e to where manage.py is located)
Like
cd mysite
py manage.py startapp polls

In CMD prompt right?, thanks
Re: Learn How To Create Websites With Python(Django Web Framework) by nelxxy(m): 11:42am On Mar 28, 2020
MichelleObama:

Like
cd mysite
py manage.py startapp polls

In CMD prompt right?, thanks
yes
Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 12:35pm On Mar 28, 2020
nelxxy:
yes

Thanks for the help, your assistance is highly needed.
Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 12:36pm On Mar 28, 2020
MichelleObama:

Like
cd mysite
py manage.py startapp polls

In CMD prompt right?, thanks

Have you solved the problem yet?
Re: Learn How To Create Websites With Python(Django Web Framework) by ColeDrain(m): 12:38pm On Mar 28, 2020
thug:
I successfully installed Django last nite but now am having difficulties in activating and creating new app. Can you kindly put more light.
I sincerely appreciate the work you are doing so far

Have you created a virtual environment and is it activated?

(1) (2) (3) (4) (Reply)

Do We Have Coding Bootcamps In Nigeria? / Faster Way To Learn Web Development. / Help Needed On API Used To Generate Wema Bank Virtual Accounts / Check In: Submit Your C++ Questions Lets Solve

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 51
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.