I deployed my app on heroku, but when I do some DB operation, this is what I get:
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
I am using Postgres and defined all details in config vars:
DB_NAME=xx
DB_USER=xx
DB_PASSWORD=xx
DB_HOST=127.0.0.1
DB_PORT=5432
and the part of code:
if request.method == 'POST':
form = form_signup(request.POST)
if form.is_valid():
full_name = form.cleaned_data['full_name']
username_email = form.cleaned_data['username_email']
password = form.cleaned_data['password']
user = User.objects.create_user(username_email,username_email,password)
return HttpResponse("Done")
What should I do?
On heroku your database does not run on localhost, but somewhere in the cloud.
Heroku exposes the postgres connection URL as DATABASE_URL
in the environment variables (check heroku config
).
You can use the dj_database_url
package from kenneth reitz to auto parse it to django settings:
import dj_database_url
DATABASES = {
'default': dj_database_url.config()
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.