2

It is my first time trying to get a Django application live on the net but I am having an issue with the URls.

The working local URL of my application is

  • http://localhost:8000/surveythree/ - This works as expected.

However when I upload my project to my hosting account I cant seem to locate the relevant page using the shortened URL as provided by the URLconf, in this case it should be /surveythree/

url(r'^surveythree/$', SurveyWizard.as_view([SurveyForm1, SurveyForm2, SurveyForm3, SurveyForm4, SurveyForm5])),   

I can locate the page if I use the full filepath however.

http://www.mywebsite.com/bias_experiment/src/survey/templates/formtools/wizard/wizard_form.html

I thought the benefit of the URLconf was to shorten the URL to something like one of the following

Is there something simple that I am missing here? If anyone could tell me what the shortened URL should be based on the above it would be great. I have been trying multiple combinations for a while now but I don't know if I am going around in circles or doing it wrong.

Thanks in advance.

Deepend
  • 4,057
  • 17
  • 60
  • 101
  • What error are you getting? – Alex May 26 '14 at 17:32
  • It is the standard 404 error. it is the same for all three of the above examples e.g. **Not Found** The requested URL /bias_experiment/src/surveythree/ was not found on this server. – Deepend May 26 '14 at 18:17
  • Why the bias_experiment/src part? Is it at your root? Why not: www.mywebsite.com/surveythree? – Alex May 26 '14 at 18:27
  • /bias_experiment/ is my shared folder on a college server. src was simply one of the examples i was using. As i said in the question http://www.mywebsite.com/bias_experiment/src/survey/templates/formtools/wizard/wizard_form.html works. But I thought with my URLconf that this should be shortened to e.g. http://www.mywebsite.com/bias_experiment/surveythree/ – Deepend May 26 '14 at 18:33
  • 1
    It seems as your apache server or whatever web server you are using isn't pointing to the django app.. you should configure the server to point requests to mywebsite.com to the bias_experiment/src/ directory. – Gabriel Amram May 26 '14 at 18:39
  • btw - the URLConf doesn't shorten URLs. it means that when a request reaches django (this is the key part, because it seems as though the request from the server doesn't reach django), that ends with the regexp in the URLConf - it will serve the configured view – Gabriel Amram May 26 '14 at 18:42
  • Thanks for the tips. I'll take a full read of the deployment docs and hopefully wont be making such mistakes again. – Deepend May 26 '14 at 19:13

2 Answers2

1

It doesn't look like you have actually deployed your site with a proper server. You can't just upload the files to any webserver and expect then to run: you need to configure a wsgi server and connect it to your app.

The documentation is here but to be honest I'd be amazed if your college server supported it at all, if all you have is a shared folder. You may be able to get it to work with FastCGI, but I wouldn't hold out a whole lot of hope.

(And even though you say that going to that long URL "works", I'd guarantee that all you're seeing is the raw HTML template. There's no way that any actual dynamic functionality will be working like that, as you'd see if you actually tried to submit the form at that URL.)

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • You are correct regarding your assumptions in the third paragraph, which means you are also correct for the first paragraph. Working out what issue was going to be my next problem, at least now i know whats wrong. I had not seen that documentation before. I will go through it now. Its a private server for a college research group so while my access is limited I'm one office away from the admin. Once I read through it I will have a better idea. Thanks. – Deepend May 26 '14 at 19:11
1

Deploying Django apps is much more complicated. To run in more "production" environment you will need to configure:

  • virtualenv to keep pip modules which your app required separate from global environment.
  • nginx for hosting static files ( you can copy them to some folder with ./manage.py collectstatic.
  • WSGI server: uWSGI or Gunicorn are both nice choices.
  • supervisor: for running and restarting WSGI and any other apps (for example celery) running in background

It's a lot for a start, so it's good to follow some tutorial and use ready to use config snippets.

daniula
  • 6,898
  • 4
  • 32
  • 49
  • Thanks for the tips, Ive been learning Django for a while but never really looked at the deployment. I'm already using virtualenv, i learned that lesson the hard way! Its an Apache Webserver so I will be taking a look at mod_wsgi in the morning and will search for tutorials. Thanks for the tips. – Deepend May 26 '14 at 22:56
  • Apache with mod_wsgi can replace nginx and wsgi from above list. Also supervisor won't be necessary until you start playing with celery. – daniula May 26 '14 at 23:03