Forums

ls command does not show folders of my website

Hi, I am trying to play with the Django API to query models created. The Django tutorial says that one needs to enter

$ python manage.py shell

I understand manage.py could be deep into my folder structure. When I try to do an ls to view the folder structure all it shows me is a ReadMe.txt. Why am I unable to see the folder structure (views, models, template files etc) from the Bash?

ls command

You don't have a project folder structure for manage.py to be in. If you did, the top-level folder would appear in the ls.

Well the Files section on PythonAnywhere does just me a project structure. How come I am unable to see that structure through bash? How then, do I get the Django ORM API to run from Bash?

Files

Bash has a concept of a "working directory" -- that is, the directory that you're in at any given time. The current value is show in the prompt. For example, in your screenshot above, your prompt is:

05:46 ~ $

The 05:46 is the time, of course, and the $ is just bash saying "please type something". But the ~ is the working directory. ~ is Unix shorthand for "your home directory", which is /home/rickson.

If you want to do stuff in a different directory, you need to change your working directory using the cd command. So, to go to the directory that you're showing in your second screenshot, which is /home/rickson/.virtualenvs/ypfvirtualenv/python-project/, then you would run

cd ~/.virtualenvs/ypfvirtualenv/python-project/

You'll see the working directory change in the prompt, and you'll find that ls now shows the files in that directory.

If you're wondering why the directory .virtualenvs isn't showing when you do an ls in your home directory, it's because it starts with a .. Directories with . at the start of the name don't show up with ls by default -- you need to explicitly tell it to list all files, by running ls -a.

As an aside -- I think part of the thing that's making this all so confusing is that you've put your project inside the virtualenv. Virtualenv directories aren't normally somewhere where you'd store your own stuff, they're just for the third-party packages you install. That's why the .virtualenvs directory has a . at the start, to hide it because it's not something you'd normally do stuff to directly.

If you move the python-project directory up to your home directory with the bash command

mv ~/.virtualenvs/ypfvirtualenv/python-project ~

(mv takes two parameters, "from" then "to)

... then you'll see it when you do an ls in your home directory. You will need to update the WSGI file to reflect the new location, though.

Hope that was all reasonably clear!