pgweb简介

pgweb是用Python语言使用 Django框架构建而成。同时该网站也使用bootstrap CSS框架以及Font Awesome 图标库。pgweb中的大多数内容都是静态的HTML模板,如果需要对web页面进行编辑,只需要对 template/pages/ 目录下的内容进行编辑。

安装

1. 准备Python环境

安装Python3.7环境

./configure
make -j24
make install -j24
[root@pgserver ~]# python3 --version
Python 3.7.10
[root@pgserver ~]# pip3 --version
pip 20.1.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

2. 准备数据库环境

cat >>~/.bashrc<<EOF
export PGHOME=/data/pg12.5
export PGDATA=\${PGHOME}/data/pg12.5
export PATH=\${PGHOME}/bin:\$PATH
EOF
. ~/.bashrc

3. 登录数据库并创建pgweb数据库

[root@pgserver ~]# psql -U postgres -d postgres
psql (12.5)
Type "help" for help.

postgres=# CREATE DATABASE pgweb;
CREATE DATABASE

4. 创建调用文件settings_local.py

[root@sungsasong pgweb]# pwd
/root/pgweb-master/pgweb
[root@sungsasong pgweb]# cat settings_local.py 
DEBUG=True
SITE_ROOT="http://127.0.0.1:8000"
SESSION_COOKIE_SECURE=False
SESSION_COOKIE_DOMAIN=None
CSRF_COOKIE_SECURE=False
CSRF_COOKIE_DOMAIN=None

5. 运行manage.py migrate

[postgres@pgserver pgweb-master]$ ./manage.py migrate
System check identified some issues:

WARNINGS:
?: (admin.W411) 'django.template.context_processors.request' must be enabled in DjangoTemplates (TEMPLATES) in order to use the admin navigation sidebar.
Operations to perform:
  Apply all migrations: account, admin, auth, contenttypes, contributors, core, docs, downloads, events, featurematrix, lists, mailqueue, misc, news, profserv, pugs, quotes, security, sessions, sponsors, survey
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0001_initial... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying core.0001_initial... OK
  Applying account.0001_initial... OK
  Applying account.0002_lowercase_email... OK
  Applying account.0003_cauth_consent... OK
  Applying account.0004_cauth_last_login... OK
  Applying account.0005_secondaryemail... OK
  Applying account.0006_communityauth_sync... OK
  Applying account.0007_all_emails_view... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying auth.0012_alter_user_first_name_max_length... OK
  Applying contributors.0001_initial... OK
  Applying contributors.0002_hide_email... OK
  Applying contributors.0003_make_email_nullable... OK
  Applying core.0002_block_oauth... OK
  Applying core.0003_mailtemplate... OK
  Applying core.0004_org_emails... OK
  Applying docs.0001_initial... OK
  Applying docs.0002_drop_doccomments... OK
  Applying docs.0003_docs_alias... OK
  Applying docs.0004_docpageredirect... OK
  Applying downloads.0001_initial... OK
  Applying downloads.0002_remove_mirrors... OK
  Applying events.0001_initial... OK
  Applying events.0002_event_badged... OK
  Applying events.0003_drop_training... OK
  Applying featurematrix.0001_initial... OK
  Applying featurematrix.0002_featurematrix_96... OK
  Applying featurematrix.0003_feature_v10... OK
  Applying featurematrix.0004_feature_v11... OK
  Applying featurematrix.0005_feature_v12... OK
  Applying featurematrix.0006_feature_v13... OK
  Applying lists.0001_initial... OK
  Applying lists.0002_listname_unique... OK
  Applying lists.0003_remove_list_externallink... OK
  Applying mailqueue.0001_initial... OK
  Applying mailqueue.0002_stagger_sending... OK
  Applying misc.0001_bugidmap... OK
  Applying news.0001_initial... OK
  Applying news.0002_news_tweet... OK
  Applying news.0003_news_tags... OK
  Applying news.0004_tag_permissions... OK
  Applying news.0005_modstate... OK
  Applying news.0006_sending_email... OK
  Applying news.0007_news_date_idx... OK
  Applying profserv.0001_initial... OK
  Applying pugs.0001_initial... OK
  Applying quotes.0001_initial... OK
  Applying security.0001_initial... OK
  Applying security.0002_cve_visible... OK
  Applying sessions.0001_initial... OK
  Applying sponsors.0001_initial... OK
  Applying survey.0001_initial... OK

6. 运行pgweb需要的脚本

[postgres@pgserver pgweb-master]$ psql -d pgweb -f sql/varnish_local.sql
BEGIN
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
COMMIT

7. 加载pgweb需要初始化的表和数据

[postgres@pgserver pgweb]$ ./load_initial_data.sh 
WARNING: this may overwrite some data in the database with an initial set of data.
Are you sure you want this (answer "yes" to overwrite)
yes
System check identified some issues:

WARNINGS:
?: (admin.W411) 'django.template.context_processors.request' must be enabled in DjangoTemplates (TEMPLATES) in order to use the admin navigation sidebar.
Installed 251 object(s) from 2 fixture(s)

8. 创建管理员访问用户

[postgres@pgserver pgweb-master]$ ./manage.py createsuperuser
System check identified some issues:

WARNINGS:
?: (admin.W411) 'django.template.context_processors.request' must be enabled in DjangoTemplates (TEMPLATES) in order to use the admin navigation sidebar.
Username (leave blank to use 'postgres'): 
Email address:
Password: 
Password (again): 
Superuser created successfully.

9. 运行服务

./manager.py runserver

解决依赖环境

使用pip 安装运行程序需要的依赖模块,由于默认的pip源非常慢,因此采用国内pip镜像源。

1. 安装pip模块

pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple  django \
psycopg2 \
pycryptodomex \
markdown \
bleach \
cvss \
requests \
pynliner \
babel \
pyyaml

界面展示

pgweb 是使用Python写的一个类似PostgreSQL网站的工具,如果自己想要写一个类似PostgreSQL的网站,可以使用这个工具完成类PostgreSQL自己的网站。