Reputation: 616
I had a Django web app (Python 2.7) project working and running on Azure App services.
I upgraded the Python to Python 3.6 (64 bit), after making sure the project is working on my local host, I deployed it to Azure.
After deployment I am getting this error:
The page cannot be displayed because an internal server error has occurred
Searched the internet and I installed the Python 3.6 extension.
In the log streamer I can see that the error is:
"ModuleNotFoundError: No module named 'django'"
I compared the new deployment to my old one and the only difference I can see is that in the new deployment, I can't see the virtual env.
Do I need to install the virtual env by myself? and if so, what will happen when I will updated my project and add libraries every time I will to do it manually ?
Upvotes: 1
Views: 1441
Reputation: 23782
Based on the error you provided: ModuleNotFoundError: No module named 'django'
, it seems you have issue with module package installing. You could refer to my work steps and check if you missed something.
Step 1: Follow the official tutorial to create your azure python web app.
Step 2: Add Python extension.
Of course,you could choose your desired version.
Step 3: Add web.config
file and deploy your web app.
<configuration>
<appSettings>
<add key="WSGI_HANDLER" value="<your project name>.wsgi.application"/>
<add key="PYTHONPATH" value="D:\home\site\wwwroot"/>
<add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/>
</appSettings>
<system.webServer>
<handlers>
<add name="PythonHandler" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\python361x64\python.exe|D:\home\python361x64\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/>
</handlers>
<rewrite>
<rules>
<rule name="Static Files" stopProcessing="true">
<conditions>
<add input="true" pattern="false" />
</conditions>
</rule>
<rule name="Configure Python" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true" />
</conditions>
<action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Step 4: Install pip plugin
in your python extension environment
.
Switch to the Kudu CMD and commands cd Python361x64 and touch get-pip.py and copy the content of the url https://bootstrap.pypa.io/get-pip.py into the get-pip.py via Edit button, then run python get-pip.py to install the pip tool.
Step 5: Install django
module and other modules you want to use.
Above two steps please refer to my previous case:pyodbc on Azure
Just for summary here, it is sorted out by changing the <add key="WSGI_HANDLER" value="<your project name>.wsgi.application"/>
to django.core.wsgi.get_wsgi_application()
.
Upvotes: 1