I am developing a web app and i want to have obviously local environment.
However I need to setup local env configs in my .env file and when I run python manage.py runserver it doesn't seem to load my env file, although heroku local does load it. Just to make sure I understand whats happening, id love to know what is the difference.
Related
The migration process runs within a docker environment.
After running docker-compose run web python manage.py makemigrations terminal showed
Migrations for 'api_app':
api_app/migrations/0004_analysis_error.py
But the file didn't show up in the local directory. I ran docker-compose run web python manage.py migrate and it even showed:
Applying api_app.0004_analysis_error... OK
But still no api_app.0004_analysis_error.py in the local directory.
I also tried making an empty migration, the same behavior occurred.
I also tried removing the changes and resetting the migrations, no changes were detected (even though there were).
The application name has been included in the [INSTALLED_APP] module in settings.py.
The issue is similar to this:
Why am I unable to run django migrations via the 'docker-compose run web' command?
When running docker-compose run it created the migration file in the new container but not copied to local.
To grab the file out of the container:
Copying files from Docker container to host
I'm not experienced with Django. I just want to get this project running on a localhost (on Mac). Normally I run python manage.py runserver inside a virtualenv but I can't do that without a manage.py file! I must be doing something obviously wrong if this project has 264 GitHub stars.
https://github.com/shacker/django-todo
How can I make this work?
First, it's almost impossible to get a project running without manage.py not just because of the server but also the migrations..
Second, the django codes in the github link especially the todo folder is an app of a django project and you need to add that on your INSTALLED_APPS in your settings.py file
setup script is used to install whole project with required dependency packages, once you done with setup script installation then you can import that project into your local project
Goto Project directory and run below commands:
python manage.py makemigrations
python manage.py migrate
python manage.py runserver
Finally u can see the project in the browser http://127.0.0.1:8000
I have a Flask web app that I'm trying to run on webfaction. The application runs fine through Gunicorn and the test server, but I can't get it to work with Apache.
I've narrowed it down to the lack of access to environment variables. If I run the app with Gunicorn, the environment variables are correct and the app works correctly. If I run the app with Apache, I can't access the environment variables.
Note: the environment variables are set correctly and exported correctly, so that's not where the issue lies. Again, it works perfectly, only not with Apache.
Any ideas on how to resolve this?
I'm following this tutorial: http://tutorial.djangogirls.org/en/domain/README.html
When I do python manage.py runserver it works fine. It also works when I run
heroku ps:scale web=1
then
heroku open
with python manage.py runserver it shows my blog posts and everything that I had added. But when I run the server with heroku open there are no posts as if the database is missing or something.
Why is that? Why do the two commands launch the same web page but with different posts/different databases?
Which brings me to my follow up question: how do I know when I need to run migrate or makemigrations again for the server? Would doing so fix the problem? And what exactly do those commands do/why are they necessary?
Thanks
EDIT:
Bonus question: Why do my posts display in descending order of time? The new posts are on the bottom of the page rather than the top. How can I change this?
There is a difference between your local development and your deployed project.
I assume you created your posts local. So they are saved local into your database. Local you use a filebased database defined in the settings 'django.db.backends.sqlite3' that means when you run manage.py syncdb the file is created with all tables inside. When you deploy your code to heroku the code is pushed to the server and runs from this place. This can be everywhere, so it can't connect to your local databasefile. For your project you has to setup a database on heroku as well. I recommend to read this article. When you want to transfer your data you can create a database dump local and load all data to you heroku database. Described here and here.
Another point, you don't run the server with heroku open or by fire python manage.py runserver. The heroku server is automatically started when your git push heroku master is done. It use the configs from your Procfile.
When you want to migrate your heroku database you has to run heroku run python manage.py migrate <app_name> than the migration is done remotely on the heroku server. You have to run this command everytime you changed a model and added a migrationfile with python manage.py makemigration <app_name>. When you did this you has to migrate you database local and remote. That means that you change the database structure to match your models. Remember the models are only a abstraction(orm) of your database.
I don't know your project but the order sees legit. Try to imagine this as rows. first row comes first. So the last entered row is on the bottom. You can change the order of the queryset with something like.order_by('-id'). So you get all entries in reverse order.
How do I use my production settings with heroku? This is my first attempt at any project deployment that I created ever, so I may be doing things completely wrong. I have a settings.py file and a settings_production file, but I can't seem to figure out how to get the production settings to work. I tried changing my manage.py from
"DJANGO_SETTINGS_MODULE", "myproject.settings"
to
"DJANGO_SETTINGS_MODULE", "myproject.settings_production"
then using the commands
git add .
git commit -m "production settings"
and I have also just tried changing DEBUG to False in my settings.py file. How do you commit changes to your settings in heroku or point to the correct file? I was able to get through the tutorial successfully, but I have not had luck trying to deploy my project. Also, should there be code that I add to manage.py that checks if it is a production or develop environment and uses the correct settings file accordingly, or do I manually change it? Still learning so I could be doing it completely wrong. Thanks for any help.
In Heroku, you can configure environment variables - they are called config vars.
The DJANGO_SETTINGS_MODULE environment variable should be set to myproject.settings_production.
Your manage.py is probably not being run in Heroku (there are other ways to run a Django app), which is why your change didn't work.