Ravaal
Ravaal

Reputation: 3359

Python Django 1.7 Ubuntu 14.04 how do I deploy a django site on azure?

I'm trying to deploy my Django site to the Azure cloud but it's not working. So far, I've gone through the tutorial here (https://github.com/Azure/azure-content/blob/master/articles/web-sites-python-create-deploy-django-app.md) with no luck.

I created my webapp. I made it a Django application. I'm using Ubuntu 14.04, Django 1.7, Git, and Python 2.7.6.

My root directory for my local django site is

/home/user/Documents/Aptana Studio 3 Workspace/Mysite/

I went into the directory and did the following commands.

sudo git init
sudo git add .
sudo git commit -m "comment"
sudo git remote add azure https://[email protected]:443/mysite.git
sudo git push azure master

It then goes through the deployment and shows it copying files but says this after a few copies.

remote: Omitting next output lines...
remote: Finished successfully.
remote: Deployment successful.

But it doesn't show that all the files are being uploaded.

In the azure portal it says that the website has been deployed, but I'm not getting my website when I go to the link; instead I am getting the Django default website.

What I need is something to happen just like this-

sudo python manage.py runserver

and have the server deploy the website at the specified address (https://mysite.azurewebsites.net).

It's not doing that. I'm wondering what's wrong and if you guys can help.

Upvotes: 2

Views: 509

Answers (2)

Ravaal
Ravaal

Reputation: 3359

So the azure webapp site itself has you deploy a git repo. Choose local git repo. After that, wait for it to load the details. Follow the instructions that they give you but also if you have any dependencies make sure you pip freeze > requirements.txt and eliminate all the excess. (You may have to search for answers on how to get a few of the dependencies to install correctly [like mysql.connector]). After that go to the directory that you want to put on the django webapp you made and follow the directions provided in azure. Put your password in.

Go to the dashboard of your webapp. Click to download the publish settings which will give you a .txt file with some important information.

Download or open filezilla. Insert the publishUrl (some ftp:// url) provided in the publish settings.txt file. Insert the userName. Insert the userPWD. Choose connect.

After that, and I know that this is just a band-aid type solution, go into DjangoWebProject and replace settings.py with the settings.py in your directory for your project. Do the same for the rest of the files in that folder (urls.py, wsgi.py, etc)

After that you can load your page, but you may not have the pretty page you created.

At this point go into the static folder which is automatically there and put all of your static directories in there.

After that you will have a nice pretty page that (hopefully) matches the one that you made. After that, make sure you git commit your changes to you local repo and every push after that should deploy just fine.

Upvotes: 2

Withnail
Withnail

Reputation: 3178

So you'll need to set up your Azure environment to know where to look for, amongst other things, your wsgi.py file. If you haven't already, you'll also need to set up a production settings file to be used, as the paths for templates, static files, etc will be off. All you've done at the moment (from your description) is copy the site to your Azure environment.

Navigating to the address and getting the default django site is normally a sign that you're getting, well, the default django app that Azure (and other one-click deployments) will put in place for you. Right now, the webserver is pointing to that Wsgi.py, I suspect, rather than your project. What's in your directory/directories when you look on Azure under that app?

The steps for setting up django on azure are canonically documented here.There are a bunch of options as to how to manage the local/production settings question, for example this question.
It's unclear from what you've said whether you've, for example, synced the database. (I'd also note that the tutorial you've linked seems to be suggesting using the devserver, which is a terrible idea.)

Edit: Ok, having installed my project on Azure in the same way, I have the same problem - the default project is taking precedence. I FTP'd into the server and you can see the structure - DjangoWebProject is the one created by the Azure installer.

Screenshot of file layout on Azure

If you look in web.2.7.config, you'll see the following:

<appSettings>
    <add key="WSGI_ALT_VIRTUALENV_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
    <add key="WSGI_ALT_VIRTUALENV_ACTIVATE_THIS" value="D:\home\site\wwwroot\env\Scripts\activate_this.py" />
    <add key="WSGI_HANDLER" value="ptvs_virtualenv_proxy.get_virtualenv_handler()" />
    <add key="PYTHONPATH" value="D:\home\site\wwwroot" />
    <add key="DJANGO_SETTINGS_MODULE" value="DjangoWebProject.settings" />

I think the issue here is that it's pointed at the wrong settings file - if I changed it to, in my example, "fieldwork.fieldwork.settings", then I think it would pick up the right settings, and consequently the right WSGI file. (You can see my WSGI file setting here: enter image description here

The one in the DjangoWebProject.settings file is: enter image description here

In the end, what i've done is replace (laboriously...) the files in DjangoWebProject with my own settings, etc. That works, but is clearly a hack, so my diagnosis that it's (the Azure proxy setting that points to the settings and consequently the wsgi.application file) pointing to the wrong project is correct, but I can't see why the instructions from the site didn't overwrite it as part of the deployment - or, for that matter, how to change that. But this may narrow it down...

Upvotes: 1

Related Questions