PDF Archive

Easily share your PDF documents with your contacts, on the Web and Social Networks.

Share a file Manage my documents Convert Recover Search Help Contact



VLapitsky ContactUs .pdf



Original filename: VLapitsky_ContactUs.pdf
Title: Microsoft Word - VLapitsky_ContactUs
Author: User

This PDF 1.7 document has been generated by / Microsoft: Print To PDF, and has been sent on pdf-archive.com on 17/03/2018 at 09:03, from IP address 93.84.x.x. The current document download page has been viewed 215 times.
File size: 2 MB (40 pages).
Privacy: public file




Download original PDF file









Document preview


By Vassily Lapitsky on March 09, 2018

How To Create
A Contact Us Form
In 30 Minutes
using Python 3.6 and Django 1.11

1

Contents
Introduction ......................................................................................................................... 4
Prerequisites And Initial Setup..................................................................................... 6
Create a Virtual Environment .................................................................................. 6
Create the Django Project and a Django App ................................................. 7
Check the Setup ............................................................................................................ 7
Understand The Project Structure .............................................................................. 9
Design Brief ....................................................................................................................... 10
Step 1 - Create The Data Model .............................................................................. 11
Create the model ....................................................................................................... 11
Create the database table...................................................................................... 12
Manage Objects with Django API ...................................................................... 12
Manage Objects with the Admin Console ...................................................... 15
Step 2 - Provide The URL Addresses ...................................................................... 20
Write a View Function ............................................................................................. 21
Add a URL Pattern ..................................................................................................... 21
Step 3 - Create The Form ............................................................................................ 22
Create a Basic Template ......................................................................................... 22
Make the View Return the Template ................................................................ 23
Create a Basic Form .................................................................................................. 24
Create a Django Form ............................................................................................. 26
Add the Form to the Template ............................................................................ 26
Step 4 – Make The Form Work ................................................................................. 29
2

Make the Form Submit the Data ........................................................................ 29
Display the Confirmation ....................................................................................... 31
Fix the Form Layout .................................................................................................. 32
Display More in the Admin Console ................................................................. 34
Step 5 - Set Up The Mailer ......................................................................................... 36
Add the Email Settings ............................................................................................ 36
Test the Delivery ........................................................................................................ 37
Integrate Email Delivery into the Views ........................................................... 38
Conclusion ......................................................................................................................... 40

3

Introduction
Django framework is a popular choice for web development. Some of the
big names who use Django:






Disqus
Instagram
Spotify
The Washington Post
NASA

... and the list goes on and on.
Django advantages:
Free-to-use and open-source.
Built on Python so you can use it alongside any Python libraries.
Resistant against many security issues out-of-box.
Excellent documentation (Django started in the news industry).
Reusability and modularity all around. You will find those concepts
implemented everywhere in Python, from the project structure to
the template engine.
 Batteries included. This includes both huge topics like support of
third-party technologies (databases, web servers and so on) and
subtle nuances like highlighting fields with invalid data on a page.






The prominent features are:
 Django ORM (Object-Relational Mapping). Provides data access
with Python. You don’t have to know SQL to get started.
 Template engine. Provides dynamic data and enables modular
page design with site-wide templates and code snippets.
 Admin console. You don’t necessarily have to develop content
editors.
It’s no surprise that I’m a big fan of Django, so I created this tutorial for
you to give the first taste of what Django is like.
 For an experienced Django and Python developer, it would take
around 30 minutes to go through this tutorial.
 If you’re familiar with Python but are still a Django newbie, this
4

tutorial would probably take around 10 hours of your time.
The tutorial will walk you through creating a basic Contact Us page. This
type of web pages is widely used on the web, and it often begins large
business processes and scenarios.

If you plan to start your own business, this is a place to stop and think.








What do I have to offer?
Who may be interested? How can they learn of my site?
How will they visit it? What types of devices will they use?
What should the site provide for their first visit?
How can I keep them interested?
What should the site provide for repeat customers?


This may also be a good place to start your project development,
especially if your business follows the B2C (business-to-customer) model.
So, here’s the plan for this document:










Prerequisites and initial setup
Understand the project structure
Design brief
Step 1 - Create the data model
Step 2 - Provide the URLs
Step 3 - Create the form
Step 4 – Make the form work
Step 5 - Set up the mailer
Conclusion

5

Prerequisites And Initial Setup
Things you must know:
 Basic Unix shell commands
 Basic HTML/CSS and Python coding skills
You must have a Mac / Linux machine with the following components.





Python 3.6
PIP installer (must be bound with Python 3.6)
Virtual environment managers (virtualenv and virtualenvwrapper)
Text editor (recommended: Atom with the Emmet plugin).

Your machine may be physical or virtual. If you use Virtual Box, make sure
you install VBoxAdditions.
Detailed information about the required setup will be available in a
separate document (currently under development).
Meanwhile, you can read the official Django documentation:
https://docs.djangoproject.com/en/1.11/intro/install/
The initial set up includes the following steps:
A. Create a virtual environment
B. Create the Django project and a Django app
C. Check the setup

Create a Virtual Environment
On your development machine, create a virtual environment for your
Django project. The terminal will display the environment’s name to the
left of the prompt.
~$ mkvirtualenv dj-env
...
(dj-env) ~$

Install Django 1.11 on the new environment. It may also install pytz
package for time zone support.
(dj-env) ~$ pip install django~=1.11
...

6

Successfully installed django-1.11.11 pytz-2018.3

Create the Django Project and a Django App
A typical Django web development project includes the central Django
project and at least one Django app. For more information, see
Understand The Project Structure.
Create the folder for your site.
Inside the new folder, create the Django project and a Django app. Note
that the example uses a dot for a simplified directory tree.
(dj-env) ~$ mkdir django_project ; cd django_project
(dj-env) ~/django_project$ django-admin startproject djpr .
(dj-env) ~/django_project$ python manage.py startapp app01

Check the directory structure. It will show a directory for your project, a
directory for your app, and manage.py, a utility for administrative tasks.
(dj-env) ~/django_project$ tree
├── app01/

...
├── djpr/

...
└── manage.py

Open the settings file (settings.py) in the project folder in the project
folder and add app01 to the list of installed apps.
INSTALLED_APPS = [
...
'app01',
]

Stop the server with Ctrl+C and migrate your project.
(dj-env) ~/django_project$ python manage.py makemigrations
(dj-env) ~/django_project$ python manage.py migrate

Check the Setup
Now you can check the setup by running the development server.
You will see a warning about missing migrations. Ignore this warning for
the time being.
(dj-env) ~/django_project$ python manage.py runserver
Performing system checks...
...
Starting development server at http://127.0.0.1:8000/

7

By default, your development server will run on port 8000, so you can
open the welcome page at 127.0.0.1:8000 (or localhost:8000). Replace
localhost with an IP address, if Django runs on a remote server.

Django works, so you can go on with this tutorial.

8

Understand The Project Structure
Web apps vary in size and complexity.
 A personal site may have several main pages (about, portfolio,
contacts).
 A corporate site may have dozens and hundreds of sections. It may
require integration with external systems, and be very complex.
To solve the challenge of complexity, a typical Django project breaks
down the functionality into Django apps.
 The Django apps implement the main business logic.
 The central project routes the users’ requests to specific Django
apps, and enables communications between the Django apps.
Django enables the communications by processing the requested URL
addresses. This is how it may happen.
1.
2.
3.
4.
5.

There is a link, say, https://mega-site.com/blog/post/23432.
The user clicks the link.
This request reaches the web server at mega-site.com.
The server strips the domain.
The server compares ‘blog/post/23432’ against the URL patterns.
This matches the pattern for the blog app.
6. The server strips ‘blog/’ and sends the ‘post/23432’ to the blog app.
7. The blog app parses this remaining URL, matches it with the view
function and sends 23432 to the view function.
8. The view checks for blog post # 23432.
9. The response will provide some HTML code and display a page in
the browser.
 If there is a post, it will be displayed in the browser.
 If there is no post, the server will return a 404 Not Found
page for the browser to display.
10. Repeat steps 1 through 9 for each request of the site’s pages.
Important takeaways:
A. URLs are important, as they define much of the web site design.
B. Words may be misleading. A single web app may include
multiple Django apps.
9


Related documents


PDF Document vlapitsky contactus
PDF Document resume jasonpehur c
PDF Document mike johnson jr resume
PDF Document virtual and physical sharepoint servers
PDF Document dmugtasimov resume upwork
PDF Document ankit 14ar10005


Related keywords