beginner Django developer here.
I started a personale project with buildout and now I wanted to test some deploying, I decided to go with heroku, but I immediately noticed that heroku works with virtualenv and a requirements.txt file. My question is, is there a way to deploy a buildout project to heroku or convert said project to use virtualenv? If yes, how can I achieve this?
Thanks
Buildout and virtualenv can work just fine together.
Upload your buildout.cfg, your bootstrap.py and use the virtualenv python to run the bootstrap.py script.
Kenneth Reitz (of requests fame, and Heroku's Python guy) has created a buildpack that does just that.
Related
New to Django, I am trying to view the website with its associated functionality generated by the project files here:
https://github.com/tomwalker/django_quiz
When I use the usual: manage.py runserver on the command prompt, it says that there is no manage.py file, and there isn't.
Worryingly, I followed the instructions for installation which suggested: Run pip install -r requirements.txt
...and my computer proceeded to de-install Django 2.0? What is that about, and can anyone explain how to restore settings if I messed them up completely.
The second part of the instructions for installation asks to change something in the INSTALLED_APPS and urls.py section, but where? There is nothing in the root directory and it doesn't specify which folder/app to do this in?
I don't quite understand how to "run" (see/view) these files and see this quiz app in process on my local host. What do I need to add? Why is the manage.py file not included?
Any explanation or something to point me in the right direction would be appreciated
The github project contains only Django apps. Not whole project. You need to integrate this in your Django project. You can run it by following below steps.
Create New Django Project
Clone github repo in your project. Run following commands in your project directory.
git clone https://github.com/tomwalker/django_quiz.git
mv django_quiz/* .
rm -rf django_quiz
Add essay, true_false, quiz, multichoice in your installed apps
Install requirements with pip install -r requirements.txt
Create Migrations
Run Migrations
Add url(r'^q/', include('quiz.urls')) in your project urls.
Run server with python manage.py runserver
Good day.
I'm a newbie to Django and I have a slight confusion:
When deploying my Django app, do I need to deploy it with all the Python 'come-with' modules, or the hosts already have them installed.
Also, I installed PIL for image manipulation. Would they also have it installed or i have to find a way to install it on their servers. Thanks in advance
do I need to deploy it with all the Python 'come-with' modules
Never do that. It might conflict with the dependencies on the server. Instead issue the following command to create a dependency file (requirements.txt).
pip freeze > requirements.txt (issue this command where manage.py is located)
On the server create a new virtual environment. Now copy django project to the server (you can do this using git clone or just plain old Filezilla). Activate virtual environment. Then change you current working directory to the where manage.py is located. to install all the dependencies issue the following command.
pip install -r requirements.txt
This will install the required dependencies on on server.
I have django project running on my machine in virtualenv. Is there a way I can deploy my project on Heroku directly? I followed steps mentioned in heroku documentation but i am kind of confused with req.txt since my project already have req.txt in virtualenv. I am new to django heroku techs. Any guidance is highly appreciated.
my project already have req.txt in virtualenv
You should not have req.txt in virtualenv. You should have requirements.txt in your project repository. requirements.txt is just a list of modules that need to be installed in the virtualenv. You create and activate a new virtualenv, then you run pip install -r requirements.txt, and it installs everything you need in the virtualenv. So requirements.txt is not part of the virtualenv, it's more like a description of how to setup the virtualenv.
If this is not clear, you may find my article, virtualenv demystified, useful.
The requirements.txt file defines what python dependencies Heroku will install. Generally speaking, what you use locally will be the same as your local development machine.
If there are differences, you may opt to have an additional file locally that contains local, development-specific packages (for example django-debug-toolbar).
First you will activate your virtual environment and then go to project root and run the command
pip freeze > requirements.txt
This will automatically add all the dependencies of your local machine in requirements.txt. Once you push the file heroku will automatically detect the changes and install them.
I am trying to deploy a django website project with 3 apps on heroku. In the heroku website it is mentioned to activate virtual environment before deploying apps. But the venv file is taking a lot of space (actually it is taking the 50% of the space of my project) and deploying it is taking a lot of time. I hope for a nice answer. :)
Whether you use a virtualenv in your local development is up to you, but in either case you'll have to specify a requirements.txt file so Heroku knows what Python packages/dependencies to install.
Creating a minimal requirements.txt is very easy using a virtualenv, as outlined in Heroku's tutorial for Django.
pip freeze > requirements.txt
I have already developed an application with Python Django and it's working, I am new to Python Django and now I need to deploy it on heroku servers, there are so many blogs and websites including heroku site that explains deploying a django app on heroku from scratch I haven't found any which talks about a running app
for example all of them need installing django which makes me confused,
this is the folder structure of my app:
myapp
|_my_app
| |_Settingd.py
| |_urls.py
| |_wsgi.py
|__webapp
|_statics(folder)
|_admin.py
|_models.py
|_views.py
The app is connecting to mysql server locally
Question(s):
Now I am totally confused, how do I have to deploy my running app on heroku? among the steps to deploy an app on heroku provided below which ones are mandatory for me and which ones I can escape and according to my folder structure where should be the location of requirements.txt or Procfile and what should be the content of them?
https://devcenter.heroku.com/articles/getting-started-with-django
Do I have to install virtualenv? and yes where should I run this command(in which folder)
I think I don't have to install django or any database api or driver for django? since they are all already installed
So the first question of yours is why the app should be running inside Virtualenv?
what's the first step? Install Django, right? Not quite. One common problem with installing packages directly to your current site-packages area is that, if you have more than one project or use Python on your machine for things other than Django, you may run into dependency issues between your applications and the installed packages. For this reason, we'll be using virtualenv to manage our Django installation. This is common, and recommended, practice among Python and Django users.
Then install and activate your virtualenv using this command...
$ virtualenv env
$ source env/bin/activate
And finally we activated the environment. Now it'll look like this
(env)rs#rajasimon-desktop:~/studio/Project$
Then i guess your second doubt what is the purpose to install django-toolbelt ?
If you are installing django-toolbelt it will install all the dependencies or package need.
it contains Django, psycopg2, gunicorn, dj-database-url, dj-static, static
Firstly Heroku natively uses postgres. Life will be easier for you if you use that locally.
If you really want to use mysql, you have two paths to follow.
1) Run mysql locally, but convert to postgres when migrating to Heroku using the mysql2psql gem, as described here: https://devcenter.heroku.com/articles/heroku-mysql
2) Use a mysql addon like https://addons.heroku.com/cleardb
However my recommendation would be to use postgres end to end, as it is baked into Heroku, and you'll be working with the default ways of using Heroku, not against the
This is my project package i am currenlty working
(env)ri#rajasimon-desktop:~/studio/project$ pip freeze
Django==1.6.5
MySQL-python==1.2.5
Pillow==2.5.3
argparse==1.2.1
django-ckeditor-updated==4.2.8
wsgiref==0.1.2
where should be the location of requirements.txt & Procfile ?
How to make requirements.txt file ?
By running below command will automatically include all packages inside txt file.
pip freeze > requirements.txt
Declare process type with Procfile
The procfile is for starting the dyno when in productioin. I always right like this..
web: gunicorn project.wsgi
So finally your project structure will look like this
myapp
|_my_app
| |_Settingd.py
| |_urls.py
| |_wsgi.py
|__webapp
| |_statics(folder)
| |_admin.py
| |_models.py
| |_views.py
|__manage.py
|__requirements.txt
|__Procfile