In production Page not Found Error when trying to access Django /admin on deployed Heroku app - django

Friends -
I have a django app (build with cookiecutter) and I have it deployed on Heroku, following these steps here:
https://cookiecutter-django.readthedocs.io/en/latest/deployment-on-heroku.html
Everything works fine and I can also create instances in the database. Now, when I try to enter the admin-page with /admin I get an 404 Page not found error.
When deploying I had this error: (which I ignored)
remote: Invalid input of type: 'CacheKey'. Convert to a byte, string or number first.
remote: --> Continuing using default collectstatic.
I ignored this error because I everything was working. Now, could that be connected or am I just missing something here?
I assume I after deployment I should be able to login to the django admin section, or am I mistaken? I set my admin url in my .env file, but still, I get this problem. Locally everything runs perfectly....
Any help or hints are very much appreciated!

Related

Internal server error running Django on Heroku accessing from browser

I think this is a simple fix, but I've deployed quite a few Django apps to Heroku and I still can't figure out what's going on.
Accessing https://dundjeon-finder.herokuapp.com/ gives me a 500 error when using the browser/curl, but if I shell into the app using heroku run ./manage.py shell I can render the views no problem. My logs aren't telling me anything (just that the response is 500) despite DEBUG being set to True, and Sentry isn't receiving an error (it has previously when the database env variable was set badly), so I'm assuming it's something to do with the way the request works.
The repo is public, any help would be much appreciated! The settings file is here.
Well it was because of using asgi instead of wsgi. I'm not sure why that caused the errors, but will do some more searching.

Django Static Folder Forbidden (403) on Nginx Digital Ocean

I've successfully followed this tutorial on digital ocean: https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04
on deploying a django app - the app works fine but one thing I noticed is that the app can't render styles in the static folder - it returns a 403. Am I missing something? Is it a server issue or do I need to configure something additionally in Django.
Please note if I run python manage.py runserver 0.0.0.0:8000 the styles render fine.
I ran into a problem where my js modules imported another module and the imported module was not loading with a 403 forbidden message. This was because in my django's settings.py I did not include AWS_DEFAULT_ACL = 'public-read'```` So they were private resources. Once the permssion is set to public-read, the 403 Forbidden``` error goes away. See the docs here

Heroku Server 500 error on particular page

Just deployed a Django app on Heroku. Everything works except for one page of my site which creates a Server 500 error (even though it works fine on my local development server).
The page raising the error doesn't do anything unusual. It makes some database calls, renders some forms, implements JQuery, etc. Any clue what this could be or how I can debug it?
Also, I thought this might be a data issue since my data in Dev doesn't match my data in production, but I checked and this doesn't seem to be the cause.
enable DEBUG=TRUE in your django settings.py file or type in console heroku logs --app your_app to get heroku server logs.
This was because I didn't include a runtime.txt telling Heroku to use Python 3 instead of 2 which subsequently raised an error in one of my views where I called super() with no args.

Heroku assets rails 4

I have just deployed a new app on heroku for the first time.
Unlike many others I had no troubles precompiling the assets. They are neatly precompiled and placed in
public/assets. I verified this in heroku bash terminal.
However when I open the project web page none of my assets are served. I verified that the hash to avoid cache stuff was correct.
I have in my application.rb added config.serve_static_assets = true but it made no difference.
There public/assets/manifest.json (pointing to the right files) but no yml and I think I read somewhere about a manifest.yml. Could this be the problem?
Any advice on how to debug this? Or what might be wrong.
Edit
In answer to the comment an example:
There is a file in the heroku app (checked with heroku bash)
public/assets/application-7744776478cb6ee3a23dd79bfcc293bd.css
my browser asks the heroku app for:
´assets/application-7744776478cb6ee3a23dd79bfcc293bd.css´
and the heroku app answers with 404 file not found.
I solved the issue by adding the gem rails_12factor
suggested in: heroku assets not found 404

Issue with Heroku, configuration variables and django using S3

I'm having a very strange issue.
I have my django project running in Heroku using S3 to store my static assets.
I wanted to use the Heroku enviroment variables by setting them as follows:
heroku config:add AWS_S3_TOKEN=my_s3_token
heroku config:add AWS_S3_SECRET=my_s3_secret
And using them with python's os module:
import os
token = os.getenv('AWS_S3_TOKEN')
secret = os.getenv('AWS_S3_SECRET')
But heroku keeps throwing me the following error:
NoAuthHandlerFound: No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV1Handler'] Check your credentials
So, I ended up writing those parameters in my settings.py file and it works fine
Why is this happening?
If I run
heroku config
I can see all my seted variables and if i do
heroku run python manage.py shell
and then
import os
print os.getenv('AWS_S3_TOKEN')
For example, it prints the variable's value.
any clue on this???
Thank you in advance
I'm not familiar with python or Django, but I'm curious.
If you try your authentication with blank strings, do you get the same error?
If so, then I suspect it's about when you're doing this authentication dance. When are you doing it? At compile time, or at runtime? (If at compile time, look at this)
The app's environment variables aren't usually available while Heroku is compiling the slug and setting up the application, they're only available once the app is running. For a Django app, Heroku will run collectstatic as part of slug compilation, which is probably why you're seeing this error.
You can make the environment variables available during compilation by enabling a Heroku Labs feature:
heroku labs:enable user-env-compile
There's more information in this Heroku dev centre article: https://devcenter.heroku.com/articles/labs-user-env-compile