Django: Why can't I get my development server to work? - django

I'm on Windows XP with the latest install of Python 2.6 (and the development server has been working up until last night). I have the path and Python path stuff all set up, and my dev server has worked forever. I recently replaced my django-trunk with a new pull from the Django trunk. I thought maybe there was an import error or something that Django wouldn't catch in one of my app's models.py so I started a new project (empty but just for testing) and it still didn't work. I restarted my computer and tried the new empty app again python manage.py runserver 8080 and went to http://127.0.0.1:8080/ and it worked ("Congrats. Django is insta..."). So I CD over to my real project and tried again and it didn't work. I'm not getting a stack trace or anything like that. I either get [17/Ja/2010 16:30:51] "GET / HTTP/1.1" 301 0 as output when I visit http://127.0.0.1:8080/ in my CMD prompt or I get nothing (even if I hard refresh, etc). What could this be?
Update (Important):
Firefox tells me Firefox can't find the server at www.127.0.0.1. even though I'm at http://127.0.0.1:8080/. Does this mean that Django is really sending a 301 to www.127.0.0.1 for some other reason?
I removed PREPEND_WWW from settings.py, and even removed all the apps (except for the django admin and preset ones) that were installed in settings.py.
Update 2: It works in Safari! How can this be? It's like Firefox is getting some sort of 301 but Safari works just fine.

yep, 301 permanent redirect is remembered by firefox, i've been stuck once on that one, restarting or cleaning history/cache didn't help, so i just ran it on another port.
edit after commenting:
assuming you use some localhost_settings.py to setup your project locally and still want to www_redirect on the production website:
try:
from localhost_settings import *
PREPEND_WWW = False
except ImportError:
PREPEND_WWW = True
i do it this way

Related

gunicorn Serve Error(500) in django 3.2 app on localhost

I'm trying to serve my Django 3.2 application using gunicorn on my localhost. First time, it ran correctly. Later, I changed DEBUG parameter to False in settings.py and I run it again. This time it gives me a server error. In terminal there is no error. See the pictures below. Why is this happening ? How to fix this ?
Error Page
settings.py
terminal
As you are trying to use it in your localhost you need to change the DEBUG = True instead of DEBUG = False and It will work smoothly

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.

Seeing Django debug 404 page despite having DEBUG = False

I have been following this tutorial along to deploy my first Django site and have successfully reached the section 'Configure Nginx to Proxy Pass to Gunicorn' which all seems to be working.
My problem is that, despite my settings.py file containing the following:
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
I am still getting Django's debug=true 404 page with the following error:
"You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page."
I changed the file to DEBUG = False after completing the 'Configure Nginx to Proxy Pass to Gunicorn' step in the tutorial by pulling the change from my GitHub repository. Am I missing an additional step with Nginx in order to turn debug off and serve a standard 404 page?
Edit: It actually seems that any adjustments I make to the settings.py file in my repository, when pulled on to the server, don't have any effect. I commented out the whole settings.py file to see if it would break the webpage; nothing happened.
I'm guess that you does't restart web server after code editing. Try to restart your Gunicorn server, when you work with django runserver command it automatically restart web server on any change in code. Gunicorn dont do this by default, if you wanted that Gunicorn also restart server automatically, run it with --reload argument. But it dose not recommended into production

Django is giving me a 404 error

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)
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.

Django. Mezzanine new project not importing all files

I wanted to start playing around with Django again (I'm not an expert in Python/Django, but I can make nice things work tho). I used Mezzanine once just to see how it worked. The 'mezzanine-project myproject' command worked like a charm as I had a nice small app running quickly. So, today I downloaded the new Mezzanine 1.3 along with Django 1.4.3 and all its dependencies (pillow, pytz, html5lib, etc) and tried to create another project so I could now work on it in a more consistent manner for personal purposes.
For my surprise, when I ran the server, I got lots of 404 errors pointing to missing /static/ files. Also, after creating the database (with manage.py createdb command), the only thing created was the static folder containing only the pictures of the predefined gallery that come along with Mezzanine. Also, there is no Log in or signup buttons as well.
I've tried making a clean install of all Python and its site-packages with the same result. I also tried copying/pasting the folders containing missing files from the /site-packages/mezzanine folder into my project, but the result was just reducing the number of 404 messages.
I've been doing an extensive research on this issue (with no luck but maybe because of the release being recent?) and even trying to contact someone on the Mezzanine IRC channel with no success.
I hope I'm not missing something silly. Do I have to change anything (note that I'm ok with the old mezzanine default settings) in my settings.py or in a specific file before running manage.py createdb command?
For the record: before running createdb, The only thing I edited was settings.py and changed the database parameters to make it work with my MySQL Server and commenting the local_settings configuration as I do not need it.
Some parameters that could be of help:
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PROJECT_ROOT, STATIC_URL.strip("/"))
By default, DEBUG is set to False in settings.py, and DEBUG is set to True in local_setting.py
Given that, if you just commented out importing local_settings.py, DEBUG would be False.
Django's development server won't serve static files when DEBUG is set to False, see the staticfiles section of the Django docs for more details.