[Tutorial] Developing an institutions data collection web front-end with python 3.6(part 4)

in #utopian-io6 years ago

images.png
image source
Repository: Python, Open Source Repository

Software: For software download python 3.0 compatible with your OS here

Difficulty : Intermediate
What you will learn:
In this tutorial you will learn how to

  • Develop a site using our code written and running it in the back-end.

  • Use Django to enact our python code for our web management system

  • Develop a basic front-end for this program

  • How to use metacharacters fo specifying URL paths

For my previous posts in the python tutorial series
-Click Here* Creating a simple calculator using python 3.8(cpython)

Creating an encryption key(Cryptography)
- Part 1
- Part 2
- Part 3
- Part 4

Curriculum for this series
Part 1 of this series
Part 2 of this series
Part 3 of this series

Tutorial
In the last three of this series we've written python code for the development of a suitable back-end for an institutions data collection. Today well enact that code for a website where we will have an interface for our front-end.

Note: Knowledge of Django technicality is Neccesary but readily available on the internet already and so would not be explicitly included in this tutorial. You can follow this link to learn about Django.

Setting up our webpage
if you already have Django installed skip this step. But if you don't, run

pip install django

This would install the latest Django to your python. To install for a previous version run:

pip install django--$1.7

This will run as long as you have pip installed to your python.
Now that we have our environment set, we have to create a folder for development.
Let's name this folder "DataSystems"
Screenshot_20180718-012739_1531878590646.png

Create this directory preferably on your desktop screen.
Then we start development by running this command line

django-admin start project datasystems 
#This starts up a new project and creates sub directories that will be readable by our python console

And then run our development server using

python manage.py runserver
# manage.py is used to run administrative functions

Django automatically created an internal IP for development which is 127.0.0.1.8000. If this development involves multiple users connected to the same network network. You can use

python manage. pay runserver 0.8000

to change the development IP
Type this into your browser and you should see a congratulations message. We then move to directing our URLs to our code.

Developing the application
Familiarity with the Django system means understanding that Django projects runs on apps. We will have to point out URLs to this application and determine what our user will see using our views.py which is created by default when you run the start project function in our terminal.
As usual, within our created folder, this is a list of directories created by default

data_systems/
    manage.py
    data_systems/
        __init__.py
        settings.py
        urls.py
        wsgi.py

We will create another folder within our data systems folder and call it system. This will house the code we've written for the past 3 tutorials.
To create this directory we will use this function while in our "Data systems".

python manage.py startapp system

This will create a directory containing the following files which will house our code.
Note: Our code can be anywhere within the data systems folder. It will still be read.

#Directories within our created folder
system/
    __init__.py
    admin.py
    apps.py
    migrations/
        __init__.py
    models.py
    tests.py
    views.py

Creating a web response and directing our URLs
We then go to our views.py folder and within it create an index function which we will want our URL to point to(this will be addressed later I'm this tutorial)

from django.http import HttpResponse
#This index will be the response whenever a URL is input

def index(request):
    return HttpResponse(<h1>Data Collection back-end</h>)

Now we create a URL folder in the system directory to direct our input. Open on your python code editor and edit like this.

from django.urls import path

from . import views
# this is to direct our URL to our index file
urlpatterns = [
    path('^https//system', views.index, name='index'),
]

"^https//system" is an application of inbuilt metacharacters from our regular expressions in python. This means that if the website starts with https//system, it should be redirected to the index folder which at this point has our heading file.

We also need to include our system file to our URL patterns. This file by default be found in the data_systems/url.py file which was created automatically when we started our project.

from django.contrib import admin
from django.urls import include, path
#Here we include our system/ folder and the path to our url.py file within the system application. 
urlpatterns = [
    path('system/', include('system.urls')),
    path('admin/', admin.site.urls),
]

This is the startup for building our backend and in the next tutorial we will learn how to include the code we've written previously into the administrative settings for our site.

You can find my Proof of work in Github

Sort:  

Thank you for your contribution.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Hello! I find your post valuable for the wafrica community! Thanks for the great post! We encourage and support quality contents and projects from the West African region.
Do you have a suggestion, concern or want to appear as a guest author on WAfrica, join our discord server and discuss with a member of our curation team.
Don't forget to join us every Sunday by 20:30GMT for our Sunday WAFRO party on our discord channel. Thank you.

Congratulations @yalzeee! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Do not miss the last post from @steemitboard:
SteemitBoard World Cup Contest - The results, the winners and the prizes

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Hey @yalzeee
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63061.76
ETH 2602.70
USDT 1.00
SBD 2.75