Question

I installed Django, and it works. I set it up so it uses my mysql database, and I started a project. So far so good.

I followed the tutorial on setting up your first Django app over at

https://docs.djangoproject.com/en/dev/intro/tutorial01/

It is a tutorial over setting up a pre-existing poll app where everything has practically been built for you. The database structure has even been handled.

I ran:

python manage.py startapp polls

python manage.py sql polls

python manage.py syncdb

I didn't receive any kind of success message so I went into my phpmyadmin, and hooray! There are new tables and rows in my database.

Their tutorial then told me to run:

python manage.py shell

and that I'd see some database stuff, but I didn't. Why could this be? I ignored it and went on to step two. I still hadn't set DEBUG in my settings.py to False so I did. Only to get a 500 error.

After some digging I read I needed to add:

ALLOWED_HOSTS = ['my ip address'];

I did this and now after running:

python manage.py runserver myip:8000

When I try to access Django in my browser I get a

Not Found

The requested URL / was not found on this server.

Obviously / changes to a different location when navigating to those places as well, but the point is I get a 404 no matter what.

So I look at my terminal and I have a yellow message in my terminal that says.

"GET / HTTP/1.1" 404 74

and there is 1 message like this for each place I tried to access.

I'm thinking there is a Python package that I don't have installed on my server?

I do not want to use ALLOWED_HOSTS ['*'] I read that this is bad practice. I did try it and it produces the same results as using my ip address in place of the * (I just wanted to add that extra piece of info in case it helps)

Was it helpful?

Solution

If you want to use the database shell, you should run the dbshell command instead of shell as in your post, like this:

python manage.py dbshell

If you run shell, you get a Python shell, where you can easily import and inspect the Python objects of your project.

On your local PC, it's better to have DEBUG = True in your settings.py. That way you don't need to bother about ALLOWED_HOSTS, because in debug mode all hosts are allowed. Secondly, when you get a 404 error in debug mode, the page will show you the valid URLs that you can try.

The Django tutorial certainly works. The only way it won't work for you is if you missed a step or mistyped something somewhere. If you start over and pay extra attention, I think it will work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top