Python is a very powerful and popular programming language which is used for Machine Learning, AI, Data Science. But if you are thinking to use this python to create a web application, which can use the all the feature of Python then Yes, we can create a web application using Python with the help of Django. Basically, Django is an open source and Python-based web framework for creating the web application. Now, Django is available with Visual Studio as well. If you are using Visual Studio 2015/2017 or higher version then you can find different kinds of python application templates are available in Visual Studio. Django Web Project template is one of them. This article will demonstrate to you how to create the first Django Python application in Visual Studio. So, let start the practical demonstration and see how to create a Django Python Web Application in Visual Studio.
Open Visual Studio 2017 or higher version and click to File > New > Project or simply press Ctrl+Shift+N. Here, you will get New Project windows which have three panels, just choose Python > Web from the left panel and choose Django Web Project from the middle panel as you can see in the following image. Give the appropriate project name and solution name, both can be different or similar as well. If you would like to change the project saving location you can change it from Location and finally click to OK.
Once you click to the above OK button, it will start creating a Django Python project for you. Next screen will ask you to set up the virtual environment for your Django Web Application. We can create this virtual environment in three different ways.
- Using "Install into a virtual environment", you can create a virtual environment and install all required latest packages like Django framework into this virtual environment directly.
- Using "Install into Python 3.7", you can directly install the all required packages into python globally, so that it will be available for all next project if you create under Python 3.7.
- Using "I will install them myself", here you can leave the setting the virtual environment and packages. You can do it later once your project will be ready.
For this demonstration, we will choose the first option as "Install into a virtual environment". It will help us and install all required packages under a virtual environment so that we can isolate this virtual environment from other environments.
Once you will choose the first option, the next screen will ask you to project the name for your virtual environment and select the base interpreter for your virtual environment. Here we will choose Python 3.7 as a base interpreter. Don't forget to check the checkbox for "Download and install packages" and click to Create button. It creates a virtual environment with the same name as you have provided and install all required packages into this.
As you can following image which shows the installation of required packages for a virtual environment like PYTZ, DJANGO etc. apart from this, it will create a "requirements.txt" file inside your solution which is nothing but a configuration file for latest Django framework.
Once it will be done with virtual environment creation and installation of required packages the project will be ready. Here is our first Django Python Web application. You can see the project structure with the following image. We have Python Environment, where we will find all the installed packages and if required we can add many more.
Sometimes, it is required to test the app in multiple environments. If this is a requirement and you have to create one more virtual environment then you can directly create it by right clicking on "Python Environments" and choose Add Virtual Environment as shown in the following image.
If you would like to install some other packages which are required for development then just right click to any of virtual environment and choose "Install Python Packages".
From the next screen, you can search your python packages in the search box and click to Run command just below to it for installing that python package. For instance, search for "pypyodbc" and click to "Run command: pip install pypyodbc" to install pypyodbc.
Let's run the Django project and see the output. To run the project, you just need to press F5 from the Visual Studio and It will start compiling the project and here we go. Python interpreter has started to run the project.
That's the output as follows. Awesome, we are able to create our first Django Python project in Visual Studio and run it.
So, today we have seen, how to create the first Django Python web application in Visual Studio.
I hope this post will help you. Please put your feedback using comment which helps me to improve myself for the next post. If you have any doubts please ask your doubts or query in the comment section and If you like this post, please share it with your friends. Thanks
You are here, it means, you have read something useful. So, If you like this article then please connect me on
Saubhagyam Posted : Last Year
Thanks for sharing amazing informative content. we have read all the information which you have published and quite amazing and informative we already bookmark this information