1

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 ?

halfer
20.2k20 gold badges110 silver badges207 bronze badges
asked Jan 16, 2019 at 9:52

1 Answer 1

1

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.

enter image description here

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().

answered Jan 17, 2019 at 8:15
Sign up to request clarification or add additional context in comments.

3 Comments

I sorted it out , one comment , i had to change the <add key="WSGI_HANDLER" value="<your project name>.wsgi.application"/> to django.core.wsgi.get_wsgi_application() and that solved the last issue i had
@NirElbaz Great, it summarized the solution in my answer. If you don't mind, you could mark it for answer for others' reference on the forum.
@NirElbaz If you don't mind,you could mark the answer to end this case.Thanks a lot.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.