跳转到主要内容

将胶水代码连接到django项目作为yunohost应用。

项目描述

django_ynh

将胶水代码连接到django项目作为yunohost应用。

此仓库是

Integration level Install django_ynh with YunoHost

欢迎提交拉取请求 ;)

特性

  • SSOwat集成(见下文)
  • scripts/install创建第一个超级用户的辅助工具
  • 使用本地生成的YunoHost包安装(称为local_test)运行Django开发服务器
  • 针对local_test“安装”运行pytest

SSO身份验证

SSOwat完全支持

  • 第一个用户($YNH_APP_ARG_ADMIN)将被创建为Django的超级用户
  • 所有新用户将被创建为普通用户
  • 完全支持通过SSO登录
  • 用户电子邮件、名和姓将从SSO数据更新

用法

install/upgrade中创建/更新第一个用户,例如

./manage.py create_superuser --username="$admin" --email="$admin_mail"

此操作创建/更新Django超级用户并设置一个不可用的密码。由于通过SSOwat进行身份验证,因此不需要密码。

settings.py中的主要部分

from django_ynh.secret_key import get_or_create_secret as __get_or_create_secret

# Function that will be called to finalize a user profile:
YNH_SETUP_USER = 'setup_user.setup_project_user'

SECRET_KEY = __get_or_create_secret(FINAL_HOME_PATH / 'secret.txt')  # /opt/yunohost/$app/secret.txt

INSTALLED_APPS = [
    #...
    'django_ynh',
    #...
]

MIDDLEWARE = [
    #... after AuthenticationMiddleware ...
    #
    # login a user via HTTP_REMOTE_USER header from SSOwat:
    'django_ynh.sso_auth.auth_middleware.SSOwatRemoteUserMiddleware',
    #...
]

# Keep ModelBackend around for per-user permissions and superuser
AUTHENTICATION_BACKENDS = (
    'axes.backends.AxesBackend',  # AxesBackend should be the first backend!
    #
    # Authenticate via SSO and nginx 'HTTP_REMOTE_USER' header:
    'django_ynh.sso_auth.auth_backend.SSOwatUserBackend',
    #
    # Fallback to normal Django model backend:
    'django.contrib.auth.backends.ModelBackend',
)

LOGIN_REDIRECT_URL = None
LOGIN_URL = '/yunohost/sso/'
LOGOUT_REDIRECT_URL = '/yunohost/sso/'

本地测试

为了在YunoHost应用的环境中更快地开发django_ynh,可以运行带有为YunoHost安装设置的Django开发服务器和urls。

例如

~$ git clone https://github.com/YunoHost-Apps/django_ynh.git
~$ cd django_ynh/
~/django_ynh$ make
install-poetry         install or update poetry
install                install project via poetry
update                 update the sources and installation and generate "conf/requirements.txt"
lint                   Run code formatters and linter
fix-code-style         Fix code formatting
tox-listenvs           List all tox test environments
tox                    Run pytest via tox with all environments
pytest                 Run pytest
publish                Release new version to PyPi
local-test             Run local_test.py to run the project locally
local-diff-settings    Run "manage.py diffsettings" with local test

~/django_ynh$ make install-poetry
~/django_ynh$ make install
~/django_ynh$ make local-test

注意

  • 将使用SQLite数据库
  • 创建了一个用户名为test、密码为test的超级用户
  • 页面可在http://127.0.0.1:8000/app_path/下访问

历史

链接

这些项目使用了 django_ynh


开发者信息

包安装/调试

请将您的拉取请求发送至 https://github.com/YunoHost-Apps/django_ynh

尝试 'main' 分支,例如。

sudo yunohost app install https://github.com/YunoHost-Apps/django_ynh/tree/master --debug
or
sudo yunohost app upgrade django_ynh -u https://github.com/YunoHost-Apps/django_ynh/tree/master --debug

尝试 'testing' 分支,例如。

sudo yunohost app install https://github.com/YunoHost-Apps/django_ynh/tree/testing --debug
or
sudo yunohost app upgrade django_ynh -u https://github.com/YunoHost-Apps/django_ynh/tree/testing --debug

例如,要删除,请调用。

sudo yunohost app remove django_ynh

备份/删除/恢复周期,例如。

yunohost backup create --apps django_ynh
yunohost backup list
archives:
  - django_ynh-pre-upgrade1
  - 20201223-163434
yunohost app remove django_ynh
yunohost backup restore 20201223-163434 --apps django_ynh

调试安装,例如。

root@yunohost:~# ls -la /var/www/django_ynh/
total 18
drwxr-xr-x 4 root root 4 Dec  8 08:36 .
drwxr-xr-x 6 root root 6 Dec  8 08:36 ..
drwxr-xr-x 2 root root 2 Dec  8 08:36 media
drwxr-xr-x 7 root root 8 Dec  8 08:40 static

root@yunohost:~# ls -la /opt/yunohost/django_ynh/
total 58
drwxr-xr-x 5 django_ynh django_ynh   11 Dec  8 08:39 .
drwxr-xr-x 3 root        root           3 Dec  8 08:36 ..
-rw-r--r-- 1 django_ynh django_ynh  460 Dec  8 08:39 gunicorn.conf.py
-rw-r--r-- 1 django_ynh django_ynh    0 Dec  8 08:39 local_settings.py
-rwxr-xr-x 1 django_ynh django_ynh  274 Dec  8 08:39 manage.py
-rw-r--r-- 1 django_ynh django_ynh  171 Dec  8 08:39 secret.txt
drwxr-xr-x 6 django_ynh django_ynh    6 Dec  8 08:37 venv
-rw-r--r-- 1 django_ynh django_ynh  115 Dec  8 08:39 wsgi.py
-rw-r--r-- 1 django_ynh django_ynh 4737 Dec  8 08:39 django_ynh_demo_settings.py

root@yunohost:~# cd /opt/yunohost/django_ynh/
root@yunohost:/opt/yunohost/django_ynh# source venv/bin/activate
(venv) root@yunohost:/opt/yunohost/django_ynh# ./manage.py check
django_ynh v0.8.2 (Django v2.2.17)
DJANGO_SETTINGS_MODULE='django_ynh_demo_settings'
PROJECT_PATH:/opt/yunohost/django_ynh/venv/lib/python3.7/site-packages
BASE_PATH:/opt/yunohost/django_ynh
System check identified no issues (0 silenced).

root@yunohost:~# tail -f /var/log/django_ynh/django_ynh.log
root@yunohost:~# cat /etc/systemd/system/django_ynh.service

root@yunohost:~# systemctl reload-or-restart django_ynh
root@yunohost:~# journalctl --unit=django_ynh --follow

项目详情


下载文件

下载适合您的平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分布

django_ynh-0.1.5.tar.gz (26.8 kB 查看散列)

上传时间

构建分布

django_ynh-0.1.5-py3-none-any.whl (27.0 kB 查看散列)

上传时间 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面