2

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://username@mysite.scm.azurewebsites.net: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.

frnhr
  • 12,354
  • 9
  • 63
  • 90
Ravaal
  • 3,233
  • 6
  • 39
  • 66

2 Answers2

2

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.

Ravaal
  • 3,233
  • 6
  • 39
  • 66
1

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

Community
  • 1
  • 1
Withnail
  • 3,128
  • 2
  • 30
  • 47
  • This didn't help. I went to the link "canonically documented here" and had no luck. I did everything step by step but one problem I did encounter was when it told me to type env/bin/pip install -r requirements.txt -- I don't have a requirements.txt file. I tried cloning the remote repo and cd into the directory and push that file to the host but I've had no luck. One thing that has changed though is that the website isn't as pretty as it was when I first created the app. It doesn't have the backgrounds and pictures not, just text and links. – Ravaal Apr 10 '15 at 17:32
  • Oh ok - if you don't have a requirements.txt file, then if you do 'pip freeze > requirements.txt in your local repo it'll generate one for you - not sure that'll help in this instance though! I'll come back after dinner for another crack at it. :) – Withnail Apr 10 '15 at 17:42
  • I did pip freeze > requirements.txt and the tried git push azure master and it says that everything is up-to-date but my website is still not loading. – Ravaal Apr 10 '15 at 17:45
  • ok I did git add . and git commit -m "lets try again" and git push azure master, it ran through a long process of downloading all the necessities but it said that the deployment failed with this message "Command python setup.py egg_info failed with error code 1 in D:\home\site\wwwroot\env\build\HTSeq Storing debug log for failure in d:/home\pip\pip.log An error has occurred during web site deployment. d:\Program Files (x86)\SiteExtensions\Kudu\44.40324.1452\bin\scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd" and now the page says "internal server error has occurred" – Ravaal Apr 10 '15 at 17:55
  • Here is the generated deployment log-- "Using the following command to generate deployment script: 'azure site deploymentscript -y --no-dot-deployment -r "D:\home\site\repository" -o "D:\home\site\deployments\tools" --python --sitePath "D:\home\site\repository"'. Generating deployment script for python Web Site Generated deployment script files" – Ravaal Apr 10 '15 at 18:08
  • I'm wondering if I am operating in the right root directory. My django app is set up like this- Mysite/Mysite-manage.py-dbsqlite3-etc.etc. Should I be doing this from the Parent directory of the first Mysite? – Ravaal Apr 10 '15 at 19:08
  • I think it's either that or your webserver (apache or nginx, I'm not sure which you're running) is pointing at the wrong wsgi.py file as mentioned above. I'm going to try deploying a site I know works on other servers to Azure using the steps in that guide and see what happens. – Withnail Apr 10 '15 at 19:38
  • I guess my question at this point is whether you were able to go to the link provided by azure and see your own Django application. Perhaps you had a "hello world" at least? – Ravaal Apr 13 '15 at 14:57
  • I had a little luck when I just completely replaced all of the files in the DjangoWebProject with all of the files in the Mysite directory but the images aren't showing up and the background and all of that stuff isn't loading. It's pretty ugly – Ravaal Apr 13 '15 at 15:53
  • I added all static files to the root directory which solved the image problem, but now I'm having issues with the admin page not loading right. – Ravaal Apr 13 '15 at 17:32
  • Yeah, I got mine running, it was ugly as well because the static files weren't in the right place. Change your settings.py according to the new location and run collect static and that should fix it,similarly the admin page. :) – Withnail Apr 13 '15 at 18:14
  • I just moved my static files to the root directory and it worked fine. The admin page needs work though. – Ravaal Apr 13 '15 at 18:37
  • Moving it all to the root is a workaround, tbh. It won't work for admin because it's not looking for the static assets for admin in the root directory. – Withnail Apr 13 '15 at 18:48
  • it's trying to get the base.html for admin from dist-packages. That's what I know for now. – Ravaal Apr 13 '15 at 19:11
  • And now I am having this problem all over again with a different application. – Ravaal Apr 13 '15 at 20:25