django and sqlite on production! my db file has nothing, why? - django

i am stuck again in one problem. i have been delevoping my project locally in django. everything works fine, and now i uploaded all project to server(virtual). now my db is not working, i mean, once i click the button which should bring data from db, it doesnot bring anything from db. can it be that i configured my sqlite on server in a wrong way?
basically i did nothing on server, so i think i should first configure my sqlite on server then it will work right? can you please help me how to do this. OS is linux. i hope, the configuration doesnot differ that much between OS versions of linux..
thanks

Have you installed your project's dependencies?
Are you running a virtualenv or system environment?
What do you mean with 'click a button', post the script behind it
Does your production environment runserver without errors?
Try the command line and check for errors:
./manage.py syncdb
errors ?
./manage.py runserver
errors ?
./manage.py shell
>> from django.contrib.auth.models import User
>> print User.objects.all()
errors ?
>> import sqlite3
errors ?

Related

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.

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.

Issue with Heroku, configuration variables and django using S3

I'm having a very strange issue.
I have my django project running in Heroku using S3 to store my static assets.
I wanted to use the Heroku enviroment variables by setting them as follows:
heroku config:add AWS_S3_TOKEN=my_s3_token
heroku config:add AWS_S3_SECRET=my_s3_secret
And using them with python's os module:
import os
token = os.getenv('AWS_S3_TOKEN')
secret = os.getenv('AWS_S3_SECRET')
But heroku keeps throwing me the following error:
NoAuthHandlerFound: No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV1Handler'] Check your credentials
So, I ended up writing those parameters in my settings.py file and it works fine
Why is this happening?
If I run
heroku config
I can see all my seted variables and if i do
heroku run python manage.py shell
and then
import os
print os.getenv('AWS_S3_TOKEN')
For example, it prints the variable's value.
any clue on this???
Thank you in advance
I'm not familiar with python or Django, but I'm curious.
If you try your authentication with blank strings, do you get the same error?
If so, then I suspect it's about when you're doing this authentication dance. When are you doing it? At compile time, or at runtime? (If at compile time, look at this)
The app's environment variables aren't usually available while Heroku is compiling the slug and setting up the application, they're only available once the app is running. For a Django app, Heroku will run collectstatic as part of slug compilation, which is probably why you're seeing this error.
You can make the environment variables available during compilation by enabling a Heroku Labs feature:
heroku labs:enable user-env-compile
There's more information in this Heroku dev centre article: https://devcenter.heroku.com/articles/labs-user-env-compile

Heroku+django: cannot find config vars locally

I am trying django on heroku, following the official tutorial and stuck at the creating celery and kombu tables locally step using python manage.py syncdb, getting following errors:
File "/my/virtual/path/django/db/backends/postgresql_psycopg2/base.py",
line 162, in _cursor
raise ImproperlyConfigured("You need to specify NAME in your Django settings file.")
django.core.exceptions.ImproperlyConfigured: You need to specify NAME in your Django settings file.
The problem is it cannot find the db I set for heroku by the config vars of heroku. When I run heroku config, it displays the DATABASE_URL of my app correctly, but when I try:
if 'DATABASE_URL' in os.environ
in python interpreter, it returns false. I also check, none of my config vars is in my os.environ. Shouldn't vars be added to it automatically? My previous steps are correct.
I searched and got a lot of solutions to detect the heroku db but they all are based on the assumption that I have the DATABASE_URL in my os.environ.
Could anyone point out where I went wrong? Any suggestion is appreciated. Thanks!
I believe the tutorial is missing some steps on how to run the app locally. If you want to sync the database locally, you should override the "default" DATABASE with the one you have on your machine. There is one similar answer in here with code sample.
visit this page
Heroku Database Settings Injection - How do I setup my dev django database?
ldiqual's answer is right.

Django manage.py runserver never finishes "validating models"

I am trying to follow the django tutorial. I am running on windows+eclipse.
When I run python manage.py runserver I get the message Validating models... and afterwards see no progress...
Am I doing something wrong?
I've got my answer in another question: can't get django to work in eclipse + windows
When I ran the server with the --noreload option, I saw that there's an exception thrown. After I fixed that, the output does complete, and says:
Validating models...
0 errors found
Django version 1.2.1, using settings 'XXX'
Development server is running at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
The shell is running the runserver process, and it won't go back to a command prompt until the server process ends. So, this sounds normal.
Is the server functioning?
You could possibly be importing something in your models.py file that is failing in another file. I had an import in a try/catch clause that caused this behavior. Installing the missing dependency fixed the problem.
This is what you're supposed to see. If you make a request to your test site (via your browser), you will see the log of the request. If you don't see that, then something else is wrong.