用django项目设置PostgreSQL [英] setting up PostgreSQL with django project

查看:185
本文介绍了用django项目设置PostgreSQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑 - 新的,类似的问题 - :
django.db.backends.postgresql_psycopg2,对于'NAME',我把数据库名称,为'USER'和'PASSWORD'我把我创建的用户名和密码..然后我给主机和端口做什么?主机我放127.0.0.1?我口5432吗这是安装PostgreSQL时收到的主机和端口。此外,当我安装PostgreSQL时,它要求我为数据库创建密码,何时使用该密码?



现在已经回答的原始问题:
我是数据库和django的新手,我正在阅读djangobook( http:// www.djangobook.com/en/2.0/chapter05.html ),我安装了PostgreSQL。



在djangobook中,它说我们会假设你我设置了一个数据库服务器,激活它,并在其中创建了一个数据库(例如,使用CREATE DATABASE语句)



我所做的是安装PostgreSQL和psycopg2 -2.5.1,然后使用以下指令创建一个用户和数据库:
https://confluence.atlassian.com/display/CONF30/Database+Setup+for+PostgreSQL+on+Windows



但是,当我到达Sett时,我停下来使用Confluence来使用PostgreSQL数据库。为了在使用django构建应用程序时,需要使用设置Confluence来使用PostgreSQL数据库才能使用数据库?

解决方案

不,您只需要第一部分,只需要一部分。



PostgreSQL是一个数据库引擎,可以为许多应用程序提供服务。 Confluence是这些应用程序之一。您正在遵循安装Confluence的指南,其中也包括安装PostgreSQL的部分。如果你只遵循PostgreSQL安装部分,那么你应该很好。



如果你遵循整个第一部分,那么你可能想要改变的一件事就是用户。 confuser 表示用户正在使用Confluence,如果您不使用Confluence,则不是这样。



一旦安装了PostgreSQL和psycopg,并且$ code> django 用户设置,告诉Django如何连接是一件非常简单的事情。如您所见,您需要设置




  • 后端至 django.db.backends.postgresql_psycopg2

  • 您创建的数据库名称的名称

  • 主机到运行PostgreSQL的计算机的IP地址;在您的情况下,您可能会在运行PostgreSQL的同一台计算机上运行Django,因此您可以使用特殊的IP地址 127.0.0.1 ,这通常意味着这个计算机,并且

  • 端口到你给PostgreSQL安装程序的任何数字(可能是5432)。



您还询问了您给PostgreSQL安装程序的密码与为Django创建的用户之间的区别。简而言之,您希望为每个应用程序创建用户,因此,如果由于某些原因,凭据被泄露,有人可以与他们进行连接,那么它们仅限于该应用程序的数据库。 c $ c> postgres 用户的密码给予安装程序不应该给予应用程序,而是用于管理:创建新的用户和数据库。 $ b

EDIT - New, similar question -: django.db.backends.postgresql_psycopg2, for 'NAME', I put the database name, for 'USER' and 'PASSWORD' I put the username and password I created.. and then what do I put for host and port? host I put 127.0.0.1? And port I put 5432? This was the host and port I received when installing PostgreSQL. Also, when I installed PostgreSQL, it asked me to create a password for the database, when do I use that password?

Original question which has now been answered: I'm new to databases and django, I was reading the djangobook (http://www.djangobook.com/en/2.0/chapter05.html) and I installed PostgreSQL.

In the djangobook, it says "We’ll assume you’ve set up a database server, activated it, and created a database within it (e.g., using a CREATE DATABASE statement)"

What I did was installed PostgreSQL and psycopg2-2.5.1 and then created a user and database using these instructions: https://confluence.atlassian.com/display/CONF30/Database+Setup+for+PostgreSQL+on+Windows

However, I stopped when I reached the "Setting up Confluence to use the PostgreSQL Database". Do I need to do the "Setting up Confluence to use the PostgreSQL Database" in order to use by database while building an app using django?

解决方案

No, you'll only need the first section, and only a part of it at that.

PostgreSQL is a database engine that can service many applications. Confluence is one of these applications. You were following a guide to install Confluence, which happened to also include a section on installing PostgreSQL. If you only followed the PostgreSQL installation part, you should be fine.

If you followed the whole first section, though, then one thing you might want to change is the user. confuser indicates that the user is being used for Confluence, which isn't really the case if you're not using it for Confluence. django might be a more appropriate user name.

Once you've got PostgreSQL and psycopg installed and a django user set up, it's a fairly simple matter to tell Django how to connect. As you discovered, you'll want to set

  • the backend to django.db.backends.postgresql_psycopg2,
  • the name to the name of the database you created
  • the host to the IP address of the computer running PostgreSQL; in your case, you'll probably be running Django on the same computer that PostgreSQL is running on, so you can use the special IP address 127.0.0.1, which always means "this computer", and
  • the port to whatever number you gave the PostgreSQL installer (probably 5432).

You also asked about the difference between the password you gave the PostgreSQL installer and the user you created for Django. In short, you want to create users for each of your applications, so if for some reason the credentials are compromised and someone can connect with them, they're restricted to that application's database. The postgres user with the password you gave the installer should not be given to applications, but is for administration: creating new users and databases, for example.

这篇关于用django项目设置PostgreSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆