My issue is that when I view my site using python manage.py runserver or foreman start, I can see my site perfectly.
However, when I git push heroku master on the surface everything appears fine as no errors are given. But when I view my site with the Heroku given site link, I do not see my updated site as I see when I view my site using python manage.py runserver or foreman start.
I am building my site using 'pinax-theme-bootstrap` and my virtualenv is on my desktop directory.
Does anyone have a solution as to why this may be the case?
Here is a list of suggestions on how I would approach this issue with Heroku.
You should try heroku restart. This restarts your application and can help pick up new changes.
I would clear my browser cache as often I do not see changes on my web page if the browser has cached them.
I would check that the git repository on Heroku matches my local one in that it has all the newest changes made on my local server.
Related
A little background:
I've been working on this project for about six months now and it's been running on Flask the whole time. Everything has been fine, multiple versions of the backend have been deployed live to support an app that's been in production for months now.
The development cycle involves writing everything locally and using Flask-Script's runserver command to test everything locally on localhost:8080 before deploying to a dev server and then finally to the live server.
The Problem: The other day my local flask instance, which runs on localhost:8080 apparently stopped respecting my local files.
I tried adding a new view (with a new template) and I got a 404 error when trying to view it in my browser.
I then tried making some test changes to one of the existing pages by adding a few extra words to the title. I restarted flask and none of those changes appeared.
I then went as far as deleting the entire views.py file. After restarting flask again, much to my dismay, I could still view the pages that were there originally (i.e. before this behavior started).
Finally, I made some changes to the manage.py file, which is where I put all of the Flask-Script commands, and they weren't recognized either. It's as if flask started reading from a cached version of the filesystem that won't update (which very well might be the case but I have no idea why it started doing this or how to fix the issue).
FYI: Browser caching shouldn't be an issue b/c I have the dev tools open with caching disabled. Plus the fact that changes to manage.py aren't being noticed shouldn't have anything to do with the browser.
You've most likely used flask in the DEBUG mode in which it auto reloads templates the app whenever a file changes.
Try using
export FLASK_DEBUG=True
before running
flask run
For more information see http://flask.pocoo.org/docs/1.0/config/#DEBUG
I was having a similar issue and deleting the .pyc files solved it for me.
Hi I am new to Django and have been googling for a whole day without any success.
Basically there is a live/working website built with AngularJS, Django and PostgreSQL (Ubuntu 14.04) and I am trying to download all the files and clone the site into my localhost (Ubuntu 14.04).
After I downloaded the folder and finished install the required packages on my localhost, I run:
python manage.py makemigrations
python manage.py migrate
python manage.py runserver
The server runs without reporting any errors.
However, some of the links are directed to a 404 page, such as this:
http://127.0.0.1:8000/city/chicago
Whereas in the live site, it would direct to the correct working page.
Can someone tell me what may have gone wrong in the process?
Thanks.
Try editing the settings.py file set the DEBUG value to True. Instead of a 404 you should get a full debug of the actual request and see what exactly is missing (I suspect missing data as #NightShadeQueen pointed).
Also you might have a look at django debug toolbar which prints the executed sql queries as well and run them against your local database to see what exactly they return.
Anything I modify on my Django app has no effect with what's live on the webapp itself. I can delete the entire project directory and my Django app still works.
With Django and Apache, I would simply enter:
/etc/init.d/apache2 restart
And any changes made to my Django application would go live immediately after Apache was restarted. But with this new Nginx, the same thing doesn't work:
/etc/init.d/nginx restart
My Django home page still shows the:
It worked!
Congratulations on your first Django-powered page.
How do I make my Python changes go live with Django and nginx?
What is your Nginx configuration? What is your WSGI runner, are you using Nginx-wsgi or the inbuilt Django 'runserver' command?
It sounds like the "it worked" page is on a separate port, and you're testing it directly -- not via Nginx. It's really easy to get the two of them confused :)
Nvm just figured it out. For Django One Click Install Image on Digital Ocean you need to run:
service gunicorn restart
After you've made all the changes and you'd like to test changes to your web app.
How to automatically monitor .py, .js and other source code files to restart a Django (or any other for that matter) application and refresh the browser when the source changes? This is possible in Rails using guard, in JS apps using grunt-contrib-watch and the accompanying livereload browser plugin. How can I do it for Python web apps such as Django?
I start my Django server with
foreman start
this is my Procfile:
web: newrelic-admin run-program gunicorn app.wsgi
as suggested by the Heroku/Newrelic docs or the usual
python manage.py runserver
The runserver method does restart the server on .py source changes, but not the browser and doesn't watch other files - I could run guard alongside it, but then I have two processes I have to take care of, whereas grunt or rake offer unified interfaces. I'm wondering what is the recommended way of doing this among Python developers?
I could not find any detailed, comprehensive documentation on this - only incomplete discussions here and there.
You don't need a browser extension to accomplish auto refreshes. Take a look at https://github.com/tjwalch/django-livereload-server.
I posted a more extensive answer about this at https://stackoverflow.com/a/36961244/2950621
It works by using a manage.py command (server) to monitor your .js and other static files. The server sends a signal to the browser via websockets. There is some client-side code injected on every page. The injected code responds to the signal and refresh the browser.
Install this django app:
pip install django-livesync
On your django settings file add something like:
INSTALLED_APPS = (
'...',
'livesync',
'django.contrib.staticfiles',
'...',
)
MIDDLEWARE_CLASSES = (
'livesync.core.middleware.DjangoLiveSyncMiddleware',
)
Beware to register 'livesync' before 'django.contrib.staticfiles' if you are using it.
Now, just start your development server:
python manage.py runserver
Check this out for more details: https://github.com/fabiogibson/django-livesync
Using python manage.py runserver is what most use. You'll have to use another tool like: http://livejs.com/ to refresh the browser itself since Django really isn't aware of it.
Frustrated with all the explicit refreshes, I created a browser extension, for both Firefox and Chrome, to automate this. The extension works with a Django app that you add to your app list in INSTALLED_APPS. You can find out more at the github repo.
Though the repo has entire source code, the extensions are also available in the respective web store. Just search for 'Django Auto Refresh'. With these, you just need to copy the app into our project's folder and include it via INSTALLED_APPS. I wanted to add a pip setup script, but haven't found the time to do it.
HTH. Apologies if this sounds like self promotion.
I tried several answers here. But the browser did not seem to show the recent changes of the code. It worked for me when I opened Chrome in Incognito Mode.
If you are using Visual studio code, then you can just use python manage.py runserver and use VS code's auto save feature.
With this feature, whenever you'll make changes in your code, it will save everything and trigger a server reload.
I'm trying to get django running on my dreahost account. I've been trying to sort of use two tutorials at once: the one on the dreamhost wiki and the one in the django book.
I installed django using the script on the wiki page, but I ran into trouble immediately while trying to work through the django book. It says:
To start the server, change into your project directory (cd mysite), if you haven’t already, and run this command:
python manage.py runserver
This launches the server locally, on port 8000, accessible only to connections from your own computer. Now that it’s running, visit 127.0.0.1:8000 with your Web browser. You’ll see a “Welcome to Django” page shaded in a pleasant pastel blue. It worked!
Those instructions seem to assume that you're developing locally, not on a shared server. Where the heck am I supposed to look for the "Welcome to Django" page after starting the server? In my webroot? No dice.
Anyway, I tried to blunder ahead through the django book to its hello world tutorial (chapter 3). But once I've edited the view file and the URLconf, I don't get a nice clean "hello world" text. Instead (as you can see) I get an "import error".
Any help would be greatly appreciated.
Don't try and learn Django via your server. Install it on your local computer, learn how it works, develop your project, and then install it on Dreamhost.
Your project assumes that 1) your app is called "mysite", and 2) mysite is a package, e.g. mysite/__init__.py exists. If either of those are false then correct your code and/or file structure.
This is an old post and am sure you have found the answer by now. I have solved this problem by using the command
python manage.py runserver mydomain.com:8080