Forums

My PythonAnywhere credentials cannot access the Django admin control panel

Hello,

I am a Django newbie, so I am currently on a steep learning curve.

I have hit a brick wall at the initial stages of trying to set up the tutorial Django app. When I hit Part 2, 'The admin site' I tried to access the admin control panel using my PythonAnywhere username and password. As a result I got back an error saying I had to enter a correct staff username and password. Since there is no step in the instructions saying how to setup a staff user, am I not correct in assuming that my PythonAnywhere credentials should be working as the correct staff credentials by default? What am I missing here?

I've tried Googling for an answer, but the only comment that made any sense to me was that the web server had to have the correct path to the virtual environment variables. As near as I can tell though I have already set this correctly in the web application control panel as:

/home/vocabulator/.virtualenvs/django18

I am sure Django 1.8 is correctly installed, but I will run any diagnostic lines anyone wants me to run to demonstrate this.

I look forward to your response. In the mean time I will try to setup a localhost copy of Django to see if this will give me some clues as to what may be going on.

I got an answer on stack overflow and I will also combine it with some information I found in another location:

  1. First you need to change directory (using 'cd <directory>') in the Bash console to the directory which contains the file 'manage.py'.

  2. You then need to create a new superuser using:

$ python manage.py createsuperuser

This will prompt for a username (or leave blank if you want to use your PythonAnywhere one), email address and password.

Once set the admin control panel should be accessible.

In my opinion instructions to this effect should be in the introductory tutorial in Part 2.

Hi there -- is this the Django tutorial at https://docs.djangoproject.com/en/1.8/intro/tutorial01/ that you're talking about?

Yes, but in conjunction with the PythonAnywhere wiki notes on this tutorial at https://www.pythonanywhere.com/wiki/FollowingTheDjangoTutorial. I realize that these notes relate to version 1.7, but I expect the situation would be similar if I had set up everything up for 1.7. I also discovered that in Part 2 it actually does tell you to create a superuser. However, the reference to looking at the Admin page in Part 1 is confusing for that reason: you can't look at the admin page before you have created a superuser.

I also found some other flaws in the tutorials from a Django beginner's perspective which I made notes on:

The instructions tell us to use the Bash console and also suggests setting up a virtual environment variable to use Django 1.7. Latter it tells us to set up a Python 3.4 project and gives instructions on using Bash to call python modules. What isn't made clear in the instructions is that Bash uses Python 2.7 by default. As a result, some of the instructions generate errors saying modules we instructed Bash to import did not exist in Python 2.7. You have to put the following extra line in the Bash setup file to make it work with Python 3.4:

alias python=python3

That's a pretty easy one-line solution to the problem, but this instruction is not found anywhere in either the Django introductory tutorial or the PythonAnywhere one.

Another issue was that you have to change directory to the location where manage.py is located before you can execute any of the multiple instructions telling you to use that utility. This will usually involve typing 'cd mysite' at the prompt on most people's installations. Again, there is no instruction drawing the reader's attention to this.

Thanks for the suggestions.

With reference to the access to the admin UI without a superuser - the creation of the superuser is part of running startproject so you must have done it in order to get a working site.

With reference to the Python version - Once the virtualenv is activated, the python in the console will be for the right version so there should be no need for an alias. We will see if there's any way that we can make that clearer.

About the directory thing - every tutorial ever written must make some assumptions about prior knowledge and understanding, otherwise they'd all start with instructions about how to turn on your computer and include a tutorial on keyboard and mouse usage. We and the Django project make an (admittedly fairly arbitrary) choice about what we'll teach users and what we'll assume they know. Understanding directories and file locations is very firmly on the "they should learn this somewhere else" side of that line.

Part 1 is about setting up the site, so of course it does not work yet. The confusing part is that it the tutorial tells you to go look at the admin page and then immediately goes on to describe how to make it look better by adjusting some references to CSS files. This assumes you can get into the admin site, which you can't if you haven't set up a superuser. Part 2 then explains how to set up a superuser. So if the writers are assuming you haven't set up a superuser until Part 2, how can they expect that you will be able to get into the admin part of the site in Part 1?

Also, I am quite fairly sure I had no superuser until someone on StackOverflow told me how to set one up because no matter how I typed in the credentials (cases as I entered them, all uppercase, all lowercase) nothing happened. However, I realised from the other thread I started in the forum that this may be because my setup steps got a little mixed up due to confusion about the virtual environment for running Django 1.8 during the the setup process. This may have led to my installation getting a little messed up, so I will restart from the beginning.

On your last point: fair enough, but at least describing where manage.py is kept so the user is aware they may need to navigate in the console would be helpful. You are marketing yourself as an organisation that is a friendly place for someone to learn Django. Beginners will stumble over points as simple as this when encountering instructions that say something along the lines of, "type manage.py..." I am new to Django, but not to Python or web development, and it still took me a little time to realise why the script was not running. I was thinking of the Bash console as being like a Python command line since I have never used Bash before.

Hi there, just stepping in while Glenn's off doing other stuff.

First off, I think Glenn was wrong about startproject creating a superuser for you. It doesn't. But the Django tutorial, in part 2, does tell you to create a superuser with the manage.py createsuperuser command, right at the beginning of part 2, before it asks you to try and change any admin CSS.

Part 1 doesn't ask you to do anything with the admin UI, I don't think: https://docs.djangoproject.com/en/1.8/intro/tutorial01/

Part 1 does explain where manage.py lives however, when it explains what startproject does.

I think the likely source of confusion is coming from the fact that it's not clear which the user should read first -- the django tutorial, or our wiki page? the answer is that you kinda have to read both at the same time, but really you have to read the django tutorial first... I'm going to try and make that clearer in our guide...

Thanks for taking us to task about this. We know it's not as easy as it could be, and we do want to be the easiest place to learn this sort of stuff. The fact that you have to use a virtualenv does make it harder than it should be, we're thinking of ways to make that easier...

Okay, yes thank you.

Django does have a steep learning curve already. In my case I did realise you needed to read both, but I think I took a wrong turn when I added the virtualenv. I thought I had corrected it, but I may have only got half way there. One possibility is you could suggest early on that people keep a copy of both tutorials open at all times while doing each step. Also is there a file people could check, or an import they could make which would tell them they have the correct files in their Django installation after the virtualenv install? This would be a helpful extra headache-saving diagnostic check that would be a little more informative than Bash giving the correct Django version number.

Good suggestion re suggesting ppl keep both tutorials open at the same time, I've added that to the help page.

re: checking whether the correct files are in the django install, I can't think of any good check on the virtualenv django version other than the print(django.get_version()), but we can suggest that the users look at their settings.py, and check that the comments and documentation links all refer to the right version. Will add that now...

hi, I have created a superuser and password on local server. used git and later downloaded it to pythonanywhere. The site is live (yay).

However, i can't log in to the site using either the username and password that works fine on local server, or the username and password for pythonanywhere. How do i solve this?

That sounds like you either haven't transferred your database to PythonAnywhere or, if you're using a file-based database (like sqlite), then you're not reading the right database file because you're using relative paths. Have a look at this help page

This is driving me crazy. I can log in easily in my local server in laptop (windows). but when i open my live site admin panel in pythonanywhere/admin, i get the standard username password dialog. i enter and it keeps saying wrong username or password for staff account.

I've answered in the other forum thread.