Files
.github
api-server
client
config
curriculum
docs
guide
arabic
chinese
english
3d
accessibility
agile
algorithms
android-development
angular
angularjs
apache
aspnet
bash
blender
blockchain
book-recommendations
bootstrap
bsd-os
bulma
c
canvas
certifications
chef
clojure
cloud-development
computational-genomics
computer-hardware
computer-science
containers
cplusplus
csharp
css
d3
data-science-tools
design-patterns
designer-tools
developer-ethics
developer-tools
devops
docker
documentation
drupal
electron
elixir
elm
erlang
fsharp
game-development
gatsbyjs
git
go
groovy
haskell
hibernate
html
ionic
java
javascript
joomla
jquery
julia
kotlin
laravel
linux
logic
machine-learning
mathematics
meta
miscellaneous
mobile-app-development
mongodb
natural-language-processing
neovim
network-engineering
nginx
nodejs
php
product-design
progressive-web-apps
puppet
python
abs-function
all-iterable
anaconda
any-iterable
args-variable
basic-operators
bool-function
boolean-operations
built-in-constants
calling-functions
class
code-blocks-and-indentation
commenting-code
comparisons
complex-numbers
containers
converting-integer-to-string-in-python
creating-guis-in-python3
data-structures
decorators
defaultdict
defining-functions
difference-between-is-and-equal-equal-operators
docstring
escape-sequences
exception-and-error-handling
files-and-io
for-loop-statements
from-x-import-y
frozenset
functions
generators
hex-functions
how-to-convert-strings-into-integers-in-python
idobject
if-elif-else-statements
import-statements
input-functions
installing-and-using-python-3
is-there-a-way-to-substring-a-string-in-python
iterators
itertools
keywords
lambda-expressions
learn-about-python-sets
len-function
list-deque
lists
max-function
min-function
more-built-in-types
mutability-and-variable-assignments
name-binding-and-aliasing-functions
nested-functions
numeric-operations
numeric-types
object-oriented-programming
ord-function
parenthesis-for-boolean-operations
powxy
python-2-vs-python-3
python-coding-standards
python-f-strings
python-resources
range-function
raspberry-pi-basics
rest-api-with-falcon
return-statement
sequence-types
set-types
setting-up-python-web-framework-django-and-flask
index.md
share-file-using-python-simple-http-server
sleep-how-can-i-make-a-time-delay-in-python
slicestartstopstep
string-methods
ternary-operator
truth-value-testing
using-pip
using-python-for-web-development
variable-names-and-binding
virtual-environments
web-frameworks-and-what-they-do-for-you
what-is-python-used-for
while-loop-statements
zip-function
index.md
r
react
react-native
redux
rest-api
robotics
rt-os
ruby
rust
sass
security
semantic-ui
software-engineering
sql
ssh
svg
svn
swift
terminal-commandline
tomcat
tools
typescript
typography
user-experience-design
user-experience-research
vagrant
vim
virtualbox
visual-design
voice
vue
vue-cli
web-augmented-reality
web-components
web-performance
web-virtual-reality
wordpress
working-in-tech
xml
portuguese
russian
spanish
mock-guide
news
tools
.editorconfig
.eslintignore
.eslintrc
.gitattributes
.gitignore
.node-inspectorrc
.prettierrc
.snyk
.travis.yml
.vcmrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE.md
README(french).md
README.md
docker-compose-shared.yml
docker-compose.yml
lerna.json
netlify.toml
package-lock.json
package.json
sample.env

43 lines
3.0 KiB
Markdown
Raw Normal View History

---
title: Setting Up Python Web Framework Django and Flask
---
In this article, we shall be discussing how to install <a href='https://www.djangoproject.com/' target='_blank' rel='nofollow'>Django</a> and <a href='http://flask.pocoo.org/' target='_blank' rel='nofollow'>Flask</a> - two popular web frameworks written in Python.
Perhaps you are already familiar with the widespread usage and community support for Python; in web-development. You might as well be aware as to what a web framework is; and the options available for Python.
2018-11-05 05:58:00 +08:00
In case these assumptions are untrue, you might want to take a look at this <a>wiki article</a>. If you are all caught up, let's go ahead with setting up Python web frameworks in your local development machine.
But it would be unfair if we completely ignore the <a href='http://docs.python-guide.org/en/latest/starting/which-python/#the-state-of-python-2-vs-3' target='_blank' rel='nofollow'>Python 2 vs Python 3</a> debate.
If you do not have Python already installed check out our <a href='https://github.com/freeCodeCamp/freeCodeCamp/blob/master/guide/english/python/installing-and-using-python-3/index.md'>Python Installation Guide</a>
## Virtual environment
Before we install Django we will get you to install an extremely useful tool to help keep your coding environment tidy on your computer. It's possible to skip this step, but it's highly recommended. Starting with the best possible setup will save you a lot of trouble in the future!
So, let's create a virtual environment (also called a virtualenv). Virtualenv will isolate your Python/Django setup on a per-project basis. This means that any changes you make to one website won't affect any others you're also developing. Neat, right?
For more information on virtual environments see the relevent section <a href='https://guide.freecodecamp.org/python/virtual-environments/' target='_blank' rel='nofollow'>here<a>.
## Wrapping Up
If you have already installed `pip` then simply:
```
$ pip install django
```
After installation it's complete we can create a new project:
```
$ django-admin startproject myproject
$ cd myproject
$ python manage.py runserver
```
Go to `http://localhost:8000`! :rocket:
We have successfully installed the web-framework of our need. However, it's not yet complete. Most web applications are content and data driven - so we need a data storage. Or, a Database, if you will.
In next article, we would be discussing how to install PostgreSQL and use it with our Python web application.
A point to ponder - we have been using `pip` heavily, but we have barely said anything about it. Well, for now, it's just a package manager like `npm`. It has some differences with `npm`; but, you don't need to worry about that now. If you are interested, do check out the <a href='http://pip-python3.readthedocs.org/en/latest/index.html' target='_blank' rel='nofollow'>official `pip` documentation</a>.
_If you have suggestions or questions, come join us on <a href='https://gitter.im/FreeCodeCamp/FreeCodeCamp' target='_blank' rel='nofollow'>gitter</a>_.