WEMAPPERS PLATFORM
Welcome, please log-in to participate in this (your) platform, by logging in you agree to abide by the rules of this forum. Until you make your FIRST Login and post.
WEMAPPERS PLATFORM
Would you like to react to this message? Create an account in a few clicks or log in to continue.
WEMAPPERS PLATFORM

WE ARE FOCUSING TO BE THE BEST SOURCE OF GEOSPATIAL KNOWLEDGE IN THE GLOBE

Who is online?
In total there are 19 users online :: 0 Registered, 0 Hidden and 19 Guests

None

Most users ever online was 140 on Sat Oct 19, 2024 9:16 pm
Discord Server
Statistics
We have 256 registered users
The newest registered user is AwezGeo

Our users have posted a total of 153 messages in 55 subjects
Top posting users this week
No user

Latest topics
» Application of remote sensing
GeoDjango :start web development with python web framework EmptyThu Aug 04, 2022 5:16 pm by Admin

» GOOD MAP MAKING TIPS TIP1
GeoDjango :start web development with python web framework EmptyFri Jul 15, 2022 8:09 pm by CarolinaLiki

» Web mapping programming Language
GeoDjango :start web development with python web framework EmptySat Nov 13, 2021 12:47 pm by Afro Teop

» WHY LIDAR REMOTE SENSING IS SO EXPENSIVE? IF YOU HAVE AN ANSWER PLEASE DROP DOWN,,
GeoDjango :start web development with python web framework EmptyMon Nov 01, 2021 11:36 am by Tumaini apolinary

» GIS analysis question
GeoDjango :start web development with python web framework EmptyWed Jun 30, 2021 11:56 am by Geoffrey venust

» We successful performed the second geotalk
GeoDjango :start web development with python web framework EmptyThu Jun 24, 2021 3:25 pm by Admin

» GIS DATA ANALYSIS
GeoDjango :start web development with python web framework EmptyWed Jun 23, 2021 12:59 pm by Admin

» How Geospatial Technologies Are Being Used to Study Light Pollution
GeoDjango :start web development with python web framework EmptyWed Jun 23, 2021 12:25 pm by Afro Teop

» DODOMA ORPHANAGE MAP
GeoDjango :start web development with python web framework EmptyWed Jun 23, 2021 11:47 am by Afro Teop


You are not connected. Please login or register

GeoDjango :start web development with python web framework

Go down  Message [Page 1 of 1]

Afro Teop



WEMAPPERS  GEODJANGO

DJANGO
With Django, you can take Web applications from concept to launch in a matter of hours. Django takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source
Install first Django and the current version is 3.8 but we can use 2.2 for formalities purpose and debugging common errors.
Make sure you have installed python 3 since python 2 expired January 2020 and you have enabled path .
Run the following commands in your command prompt

1.Install virtualenv
#install virtualenv
pip install virtualenv



As from my PC you can see I already installed virtual environment
2.Make directory in your desktop
cd desktop
mkdir Django
cd Django




3.Create virtual environment myenv in your directory
python -m venv myenv



4.Activate your vrtual env
(windows):myenv\scripts\activate

5.Install Django
pip install django==2.2.7
#verifying
import django
print(Django.get_version())
Creating a project
From the command line, cd into a directory where you’d like to store your code, then run the following command:

django-admin startproject mysite




The above project created the following python files. You can check files in mysite by running following commands as shown below
cd mysite
cd mysite
dir



The outer mysite/ root directory is a container for your project. Its name doesn’t matter to Django; you can rename it to anything you like.
o manage.py: A command-line utility that lets you interact with this Django project in various ways.

o mysite/settings.py: Settings/configuration for this Django project.


o mysite/urls.py: The URL declarations for this Django project; a “table of contents” of your Django-powered site.

Let us first register our project to our database.Django web framework comes with its own database ,the sqlite3 database
Run: python manage.py migrate



Creating our first App
First ensure you are in the right directory that has the manage.py file

django-admin startapp wemapper or python manage.py startapp wemapper


The wemapper that we have created have default python file that Django generates. We can take a look at the files
Run the commands in cmd:

cd wemapper
dir




• admin.py :this file registers models that are generated in models.py file
• init_.py: tells Python that this directory should be considered a Python package.
• models.py: In this file, we'll create models for our application.
• views.py: In this file, we'll create our views to display in our templates
• test.py,apps.py files we wont use them in this tutorial

Create super user
Run:
python manage.py createsuperuser
Then fill in the credentials(username,email,and password)



Let now dive in our text editor,am using sublime text but there are others that also work well like visual studio,atom,pycharm,use what makes you comfortable

First we shall register our app in INSTALLED_APPS in the setting.py file then run python manage.py migrate in our cmd

Setting.py



Run our project in our localserver
Run: python manage.py runserver




And hurray we have our project running in our localhost 127.0.0.1:8000



Lets login into our account 127.0.0.1:8000/admin



And we have our page



Lets create models and register them.
Move to our models.py file in Django directory in our text editor


We have our model with :
• class mapper -we are using the Django models to define our class
• name – which is a character field with a max length of 200 character
• country – charaterfield
Registering our models in admin.py file
First we import the model mapper : from mysite import Mapper



• line 1: import admin from Django.contrib
• line 2: we import our model Mapper
• line 4: creating our class admin
• line 5 : designing how we will view our models
• line 7 : registering our admin

Register the changes by :
python manage.py migrate
python manage.py makemigrations
python manage.py migrate
And lastly fire up our server
python manage.py runserver
check your browser through 127.0.0.1:8000/admin



Save our first incidence



Next we shall learn more on creating suitable environment for creating maps in Django
Ineed you to install this setup:
1. Postgresql
First, download the latest postgres from the EnterpriseDB website.
After downloading, run the installer, follow the on-screen directions, and keep the default options unless you know the consequences of changing them
And note that postgres creates both a new windows user to be postgres service account and a postgres database superuser,you will be prompted once to set the password for both accounts and remember it
     2. PostGIS
From within the Application Stack Builder (to run outside of the installer, Start ‣ Programs ‣ PostgreSQL 9.x)
select PostgreSQL Database Server 9.x on port 5432 from the drop down menu.
Next, expand the Categories ‣ Spatial Extensions menu tree and select PostGIS X.Y for PostgreSQL 9.x.
After clicking next, you will be prompted to select your mirror, PostGIS will be downloaded, and the PostGIS installer will begin.
Select only the default options during install (e.g., do not uncheck the option to create a default PostGIS database).
3.Psycopg2
The psycopg2 Python module provides the interface between Python and the PostgreSQL database.For this just run pip install psycopg2 in your command prompt

4.OSGeo4W
This helps to install the PROJ.4, GDAL, and GEOS libraries required by GeoDjango. First, download the OSGeo4W installer and run it.
Select Express Web-GIS Install and click next.
In the ‘Select Packages’ list, ensure that GDAL is selected; MapServer and Apache are also enabled by default, but are not required by GeoDjango and may be unchecked safely.
After clicking next, the packages will be automatically downloaded and installed, after which you may exit the installer.

i have attached a word document with pictures to help you work effective .In case you need clarification just ask




THANKS AND SEE YOU NEXT SESSION

AUTHOR : FRANCIS ODERO(Afro Teop)
Attachments
GeoDjango :start web development with python web framework Attachmentdjango.docx
django
(995 Kb) Downloaded 85 times

Admin and Afro Teop like this post

Afro Teop



enjoy your coding fest

Admin and Afro Teop like this post

Afro Teop



did anyone got a problem and needs clarification

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum