I'm currently trying to upload my django app to pythonanywhere and i keep running into errors with my wsgi application, it says "sys" is not defined. I have correctly followed all the steps in the manual that pythonanywhere provides, yet it is still not working. I want to know if anyone has successfully uploaded a django app with pythonanywhere and how he/she got it done; or if there are better alternatives i can explore. Thanks. I would be waiting for an answer.
Pythonanywhere advice to set up a virtual environment, in which you install all dependancies. Have you done so?
Related
I've never worked with Django before so forgive me if a question sounds stupid.
I need to develop a web application, but I do not want to deploy it on a server. I need to package it, so that others would "install" it on their machine and run it. Why I want to do it this way? There are many reasons, which I don't want to go into right now. My question is: can I do it? If yes, then how?
This is possible. However, the client machine would need to be equipped with the correct technologies for this to work.
When you launch a web app on a server (live), the server is required to have certain settings and installs. For example, a Django web app: the server must have a version of Django installed.
Hence, whichever machine is running your web app, must have Django installed. It presumably also needs to have the database too. It might be quite a hassling process but it's possible.
Just like as a developer, you may have multiple users working on 1 project. So, they all need to have that project 'installed' on their devices so they can run it locally.
You need to either use a python to executable program, with Django already in it. The website files you can place into the dist folder or whatever folder has the executable in it. Then you can compress it and share it with others (who have the same OS as you).
For an example:
You have this script in Django (I'm too lazy to actually write one), and you want to share it with someone who doesn't have Python and Django on his/her computer.
I'm currently learning Django and getting a decent grasp of it. I know you can start the server with python manage.py runserver. But then there is also heroku ps:scale web=1 followed by heroku open to open the web page at the subdomain you chose on the host herokuapp.com. What is the point of using heroku vs just runserver? When it comes time to deploy to production is that what heroku is used for as I read it was for deployment? What is exactly is heroku used for and what are the reasons? When creating a professional django web site/application is heroku required or just very useful? If so why? I don't really understand the reason for using heroku. And I'm curious what the best practices are for django and whether they include using or not using heroku.
Aside from the heroku question, what are the best practices for django as far as setting a domain name and such (other than the herokuapp.com subdomain name) and also as far as what other components/software solutions are worth using with django?
One of the things I'm working on is an FTP portal on the website that people can login to and upload files. Does django have plugins/python modules for such a thing or must it be done custom? Which brings me to my final question, What kind of addons/modules does django offer to avoid reinventing the wheel when implementing a django website/app's certain features?
The tutorial I'm following: http://tutorial.djangogirls.org/en/django_orm/README.html
has helped me get a grasp on django, but I'm curious about the more advanced parts of it. Such as custom modules, custom styling, custom scripts (whether they are js or strictly python).
If someone could point me in the right direction or offer any suggestions it would be much appreciated. The tutorial has me using the modules: dj-database-url, whitenoise, gunicorn, python-dateutil, psycopg2 , requests. I know what some of them do, but what is the purpose of psycopg2, whitenoise, dateutil, and dj-database,url? Are there any other modules worth using?
Sorry for the wall of questions, but I'm trying to understand django as best I can so that I can do a correct assessment when putting together a django project.
Thanks in advance.
EDIT, final questions:
1) Also when i used heroku they gave me a subdomain at herokuapps.com Can I set my own URL and still use heroku?
2) And last but not least, heroku makes you register and gives you a subdomain on herokuapp.com Is there a way to use heroku with your own domain rather than the one they give you? Is there a specific way to do it?
EDIT 2:
When I do runserver it works fine, but when i run it with heroku ps:scale web=1 and then heroku open it opens but only shows the title at the top of the page, and no content. Not sure exactly why that is. Can someone explain the difference between runserver and heroku ps:scale web=1 followed by heroku open??
python manage.py runserver is only for development. Never use it in production.
Heroku makes it super easy to deploy your Django code. You only need some configs and git push heroku master. But it's not the only way to deploy your code. You can also set up a server with a webserver like Nginx, Gunicorn as WSGI server, and a database of your choice. To set things up, you need to know something about Linux and the command line.
So if you don't know how to set up a server, Heroku can be very useful.
Heroku supports custom domains, and it's easy to set up.
As Mikeec3 mentioned, "Two Scoops of Django" is a very good read.
If you are looking for django packages, www.djangopackages.com is a good place to start.
psycopg2 is for postgresql usage with your app. White noise allows you to serve your staticfiles without nginx if using gunicorn. Requests is an easy to use urllib2 library with pythonic calls to work with apis from other websites.
If you want to do some testing with say facebook logins Heroku is a great place to go to, especially if you need a url outside of localhost.
My suggestion is you read Two scoops of Django http://twoscoopspress.org/products/two-scoops-of-django-1-6
It goes over alot of best practices and serves as a great tutorial after polls. I suggest also incorporating django-bower into your project. Ill list a few great things to add.
Django Bower: https://github.com/nvbn/django-bower - Helps organize static files
Crispy Forms : https://github.com/maraujop/django-crispy-forms - Great form rendering, great with bootstrap
Django Rest Framework: https://github.com/tomchristie/django-rest-framework - REST APIs
These are just to start, there's alot to learn.
I have a Django project with 1 app that is working locally and I am trying to make it work on the server but I imagine I am still missing something...
The steps I have followed are:
1) create a virtualnev
2) Install django and the libraries I need
3) copy my local project to the server, keeping the same directory structure
4) create the file passenger_wsgi.py (python passenger_wsgi.py did not return any error)
After this do I need to do anything like python manage.py runserver? Or with this I should be already able to see the site through mydomain/my project/ my app (when I do ot just get an error 404)?
I have read the django book and followed the tutorial, but this part is not well described anywhere...
Thanks in advance for any help!
Deployment is explained in the documentation.
You need to actually serve your application with some kind of HTTP server and something to run your python code. Some of the possible combinations are:
nginx with uWSGI
Any web server as reverse proxy with gunicorn
Apache with mod_wsgi
Your hosting service may or may not give you the choice or even the possibilty to do this.
There is a list of Django friendly hosters in the Django wiki.
Well firstly you might want to go through the previously asked questions.
When you are deploying using passenger you do not need to run manage.py runserver , etc. The passenger_wsgi file should take care of it.
You might want to check this link out, in the first answer also contains link to Dreamhost which details quite extensively on how to achieve the same.
Visit Deploying Django app using passenger
From my personal experience I found Nginx and uwsgi setup to be much more easier to handle and work and debug in the logs, but this is subjective to your needs and platform you may have.
I have been having some problems with deploying my django app to heroku. I have triple checked the getting started guide several times and I am getting quite frustrated. The most annoying thing is that I don't get any errors during deployment, in heroku logs or during local deployment. Here is an SO question with more details.
The easiest solution at this stage would probably be to reverse engineer a minimal working django app which I could push straight to my heroku repo without any extra config.
(The smaller the app the better a simple <h1>hello world</h1> would do but it would need to include venv, requirements.txt and of course Procfile)
Thanks
Take your pick. Either of these should work for you.
https://github.com/auzigog/django-template-heroku
https://github.com/cyberdelia/django-heroku-template
You can try http://django.ironcoder.me - visual composer, which deploys working Django app to your heroku account.
I was unable to upload to an AppEngine as appcfg was telling me :
This application does not exist (app_id=u'xxx').
I was only a developer on the AppEngine, so as I was just testing I created a new AppEngine where I was the owner but I still get the same message on a newly created AppEngine.
The fix I found was to add the parameter --no_cookies:
appcfg.py update --no_cookies MyProjectDirectory/
This can happen when you upload AppEngine applications from different Google accounts on the same computer.
You have to log in in your gae account and create an application before you upload it, and your app_id has to have the same name as you app. You can't just upload it.
So go here, create your app, for example "example_app" and set the app_id=example_app and everything should work :)
The same problem occurs with the Java/Eclipse plugin version of App Engine. The 404 happens when you're logged in to the wrong Google account from within the plugin. In that case, look at the bottom-left of Eclipse to see what account you're currently using.
Regarding the Python command line updater, if your cookies indicate that you're logged in to a Google account that doesn't have access to the application you're updating, then that would explain why ignoring those cookies by using "appcfg.py update --nocookies" fixes it.
This is really old, so I wouldn't be surprised if this isn't picked up by the poster, but I wanted to ensure that I have a reference for the next time I have the issue.
I had this issue. My problem ended up being that I had not invited the user that I was authenticating as to be a developer on the project. In fact I had just created the user and not even logged on yet.
I logged on to the google infrastructure as the new user, then added the new user as a developer on the application. I was then able to upload the app.
Tried to upload to the app this morning (first time i've tried since Friday) and it just worked (first time...!)
No idea what the issue was as I haven't done any work on this over the weekend so everything should have been the same as it was on Friday.
I got the same error message trying to make the first deployment of a Python Application using a Google Apps account.
In my case the problem was caused by the fact that my 2-way authentication is enabled.
With 2-way authentication enabled you need to generate an authentication password in your Google Account Management Application and use it to do the deployments.
this way worked:
modified the app.yaml to specify the application: some_id
python appcfg.py update ../some_application/server/python
I fixed this problem by editing my app.yaml file to have the correct application name. In the app.yaml file where it says 'application:[insert app name here]', I had to change the [insert app name here] part. I'm not sure why the name was wrong, but I do remember toying around with it before while attempting to fix a different bug. The way I figured out the proper name was to go to my applications in my GAE admin console and look to see what the app's name was there. Hope this helps anyone else that runs into this same problem :)
If you are using --oauth2 make sure that you are logged into the correct account when generating the token.
appcfg.py --no_cookies --oauth2 --email=myemail --noauth_local_webserver update .
I navigated to my app engine directory folder and ran the above command. This deployed it successfully from the command line for me (Mac OSX terminal)--although I still couldn't deploy from app engine launcher. I believe Launcher still thinks I'm running off port 8080. However, running dev_appserver.py --port=11080 .doesn't fix this issue for me-- what ended up solving it was just removing the directory from the app engine launcher then just re-adding it.
What worked for me is to use the project id from the google app engine console instead of the project name in app.yaml
Posting Ric Moore's comment in the selected answer because that is a valid answer and it worked in my case (and hopefully it helps someone else having the same issue spot it quickly).
I have an alternation solution - in the Google App Engine Launcher select from the menu Control > Clear Deployment Credential. Then when you click Deploy it will take you through the auth flow again and you can select the correct account. - Ric Moore
I had this issue and I simply needed to run 'gcloud app create' for this project within the console console. Screenshot
Previously I don't think this step was needed.