Python para desenvolvimento web

Python for web development

If you're looking to add a new language to your web development toolkit, you can't go wrong with Python.

Desenvolvimento Web em Python

beginner guides for non-programmers listed.

However, beyond just learning the Python language, you will also need to learn about frameworks and how to use them with Python.

What is a framework? Simply put, a framework is a platform for developing software applications. When it comes to Python, the framework is a means of developing web applications that include libraries and other types of code so that developers don't have to write everything from scratch.

Web development in Python with Django

The most popular Python framework is Django, which is a free and open-source web framework that follows the Model Template Views architecture. Django is one of the oldest frameworks still in use and is responsible for making more than 12,000 active projects a reality. And because Django covers the entire web development stack, it's often a one-stop shop for web developers.

Python web development projects

There are many large companies that use Python for various projects. Some of the top companies include:

  • Industrial Light and Magic uses Python to control a huge production pipeline.
  • Google App Engine is written in Python.
  • Instagram uses Python/Django extensively.
  • Spotify uses Python for data analysis.
  • Netflix uses Python to power machine learning.
  • The entire Dropbox stack is written in Python.
  • Stripe uses Python to develop APIs.

Python web page example

To create an example web page in Python, you would need a Linux server running Apache. You would also need to install Apache and the required dependency with the command:

 sudo apt-get install apache2 libapache2-mod-python -y

With everything installed, create a new configuration file with the command:

 sudo nano /etc/apache2/sites-available/python.conf

In this file, paste the following:

LoadModule python_module /usr/lib/apache2/modules/mod_python.so
 <Directory /var/www/html/python>
    AddHandler mod_python .py
    PythonHandler hello
    PythonDebug On
 </Directory>

Save and close the file.

Enable the configuration with the command:

 sudo a2ensite python

Enable the Python Apache module with the command:

 sudo a2enmod python

Restart Apache with the command:

 sudo systemctl restart apache2

Create a new directory with the command:

 sudo mkdir /var/www/html/python

Create a new file in that directory with the command:

 sudo nano /var/www/html/python/hello.py

Paste the following into this new file:

 from mod_python import apache
 def handler(req):
    req.content_type="text/plain"
    req.write("Hello, World!") 
return apache.OK

The code above uses Python to print the text “Hello, World!” in the browser. Save and close the file. Change the ownership of this file with the command:

 sudo chown www-data:www-data /var/www/html/python/hello.py

Point a web browser to

You should now see Hello World! printed in your browser.

Congratulations, you have just created your first web page using Python.

Conclusion

If you're looking to add a new language to your web development toolkit, you can't go wrong with Python. Not only is it very easy to use, but it is also flexible, powerful and used by companies all over the world. Once you have a solid understanding of this language, you can work with one of the many outsourcing development companies that are always looking for the best talent available.

If you liked this article, check out one of our other Python articles.

  • What can a good Python developer do to help your company?
  • How to hire a Python programmer
  • Is Python good for software development?
  • JavaScript vs Python: A Comparison and How to Choose
  • Top 9 Python Libraries for Machine Learning
  • Python and machine learning

Source: BairesDev

Related Content

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.