Wagtail superuser unable to log in to CMS - django

I'm new to Wagtail and django. I've completed the https://learnwagtail.com/wagtail-for-beginners/ course and managed to get my site up and running on Digital ocean, however I'm unable to login to the admin area. I have tried using the superuser credentials that were used locally. I have also tried multiple times to create a new superuser with:
python manage.py createsuperuser
and while the process appears to work successfully in the terminal (I'm logged in via SSH to my DO droplet), I continually receive the 'Your username and password didn't match. Please try again.' message when attempting to log in with the newly created username and password. If I use the shell to check users I can see my newly created user exists. I have also tried using
python manage.py changepassword myusername
to change the password on the previously created superusers, but again, while the process appears to work successfully in the terminal I continue to receive the error message when attempting to log in. Can anyone point me in the right direction as to what I might be missing or doing wrong here? And / or how I might best debug the issue? Thanks in advance!

You might need to set up a Site that matches the domain on which you're accessing your site. In the command line, try this:
import wagtail.core.models.sites
s=Site.objects.last()
s.hostname='yourdomain'
s.site_name='verbose site name'
s.is_default_site=True
s.save()
If you don't already have a site in the database (or just want to add another one), then do s=Site.objects.create() instead of Site.objects.last()place the three properties into thecreate` statement as keywords.

I needed to make sure my manage.py commands were picking up my production settings. So running:
DJANGO_SETTINGS_MODULE=mysite.settings.production ./manage.py createsuperuser
and NOT:
python manage.py createsuperuser was the solution.

Related

FATAL: password authentication failed for user 'xxx' error when migrating to a postgresql db in RDS

I am trying to migrate to a PostgreSQL db in RDS from Django. The db was set up successfully but when I run python3 manage.py migrate I keep getting the error 'FATAL: password authentication failed for user'. The user name that it mentions is not the master username from RDS which is the same as my USER in settings. I have a .env file with the USER, ENGINE, PASSWORD etc that is being read correctly apart from the fact that it is not referencing the USER. It is referencing the username I use to log onto the computer which I also used when I set up a superuser in the venv.
I have tried logging out from superuser which did nothing. I also tried deactivating the venv which seemed to solve the authentication issue though obviously none of the modules within the venv uploaded so I got errors from that.
I tried changing the password in RDS but it is still trying to connect using the wrong user. I also tried making a new venv but still got the same error. The NAME in settings is set to postgres.
Has anyone else had this issue?

Django Admin does not work after deployment Heroku

After deploying my application the admin of the website does not work. I am able to use the website, create an account and do all the crud, but the admin does not work.
1 - I created the superuser with
python manage.py createsuperuser
2 - I deployed and tried to access the admin
https://djangotodowoo.herokuapp.com/admin
Although, every time that I try to access this page it redirects to:
https://djangotodowoo.herokuapp.com/admin/login/?next=/admin/
I am not sure if that's the problem, but it's a hint at least.
This is happening because I have on my settings.py the following line
LOGIN_URL = '/login'
That checks if someone is trying to access a page without login and redirects to the login page.
I am not sure what the problem actually is, any ideas on how to solve the issue?
Thank you very much folks!
I found out that everything was working locally, the reason I was not able to log into the admin with my admin account is that I have to create a superuser on the Heroku side as well.
The solution was:
Create Heroku Super User
heroku run python manage.py createsuperuser

What is my user and pass? Deploy django on AWS EC2 but can not login admin

I've followed this youtube instruction from amazon to deploy django web app to AWS EB EC2. The website successfully ran. But I can not login to admin. The admin that came with django polls example. I recall that during the setup process, it prompt me for RDS setup and since my web app use MySQL, I had to pick RDS setup. When I setup the RDS, it did not prompt me to create a user, but only prompted me to create a password, which dutifully I did.
https://www.youtube.com/watch?v=YJoOnKiSYws
Similar instructions can be found on AWS, too.
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Python_django.html
I've tried username 'root' and password is 'blank' which works on my local pc, but of course that would make things too simple.
After that attempt failed, I did some searching in EC2 and RDS dashboard on AWS, and I found username=ebroot.
So I tried username 'ebroot' and password [rds_password_from_setup], but that didn't work.
I've tried many other combinations of usernames and passwords but nothing works. This might be a stupid question to ask the online community, but what do you suppose is my username and password that RDS might accept?
In order to create an admin user for my Django app on Beanstalk I created a custom Django command that I invoke in containers_commands, so there is no need for human input at all! Moreover I defined the user/password as environment variables so I can put my code under version control safely. The implementation of my command is something similar to this:
import os
from django.core.management.base import BaseCommand
from com.cygora.apps.users.models.User import User
class Command(BaseCommand):
def handle(self, *args, **options):
username = os.environ['SUPER_USER_NAME']
if not User.objects.filter(username=username).exists():
User.objects.create_superuser(username,
os.environ['SUPER_USER_EMAIL'],
os.environ['SUPER_USER_PASSWORD'])
then in my beanstalk config:
container_commands:
02_create_superuser_for_django_admin:
command: "python manage.py create_cygora_superuser"
leader_only: true
ps: if you never created a custom Django commands before, all you have to to is to create a package: management.commands in your desired app (ie: /your_project/your_app/management/commands/the_command.py), Django will load it automatically (and you can see it when typing python manage.py --help)

Configuring postgresql database for local development in Django while using Heroku

I know there are a lot of questions floating around there relating to similar issues, but I think I have a specific flavor which hasn't been addressed yet. I'm attempting to create my local postgresql database so that I can do local development in addition to pushing to Heroku.
I have found basic answers on how to do this, for example (which I think is a wee bit outdated):
'#DATABASES = {'default': dj_database_url.config(default='postgres://fooname:barpass#localhost/dbname')}'
This solves the "ENGINE" is not configured error. However, when I run 'python manage.py syncdb' I get the following error:
'OperationalError: FATAL: password authentication failed for user "foo"
FATAL: password authentication failed for user "foo"'
This happens for all conceivable combinations of username/pass. So my ubuntu username/pass, my heroku username/pass, etc. Also this happens if I just try to take out the Heroku component and build it locally as if I was using postgresql while following the tutorial. Since I don't have a database yet, what the heck do those username/pass values refer to? Is the problem exactly that, that I need to create a database first? If so how?
As a side note I know I could get the db from heroku using the process outlined here: Should I have my Postgres directory right next to my project folder? If so, how?
But assuming I were to do so, where would the new db live, how would django know how to access it, and would I have the same user/pass problems?
Thanks a bunch.
Assuming you have postgres installed, connect via pgadmin or psql and create a new user. Then create a new database and with your new user as the owner. Make sure you can connect via psql with the new user into to the database. you will then need to set up an env variable in your postactivate file in your virtualenv's bin folder and save it. Here is what I have for the database:
export DATABASE_URL='postgres://{{username}}:{{password}}#localhost:5432/{{database}}'
Just a note: adding this value to your postactivate doesn't do anything. The file is not run upon saving. You will either need to run this at the $ prompt, or simply deactivate and active your virtualenv.
Your settings.py should read from this env var:
DATABASES = {'default': dj_database_url.config()}
You will then configure Heroku with their CLI tool to use your production database when deployed. Something like:
heroku config:set DATABASE_URL={{production value here}}
(if you don't have Heroku's CLI tool installed, you need to do it)
If you need to figure how exactly what that value you need for your production database, you can get it by logging into heroku's postgresql subdomain (at the time this is being written, it's https://postgres.heroku.com/) and selecting the db from the list and looking at the "Connection Settings : URL" value.
This way your same settings.py value will work for both local and production and you keep your usernames/passwords out of version control. They are just env config values.

Django - accidently removed superuser

I am using Django 1.4.5 and accidentally deleted the superuser. How can I recreate the superuser account for an existing project? I found tutorials that show to do it when initially setting up a project but can't figure out how to create a superuser for an existing project.
I did try django-admin.py createsuperuser in the terminal without any luck
I apprecite the time and feedback.
You can invoke this command through manage.py
./manage.py createsuperuser