我有一个 django 项目。Settings.py:STATIC_URL = 'static/'STATIC_ROOT = 'static'MEDIA_URL = '/media/'MEDIA_ROOT = BASE_DIR / 'media'我已经执行了 collectstatic 并且一切正常。现在...
我有一个 django 项目。
设置.py:
STATIC_URL = 'static/'
STATIC_ROOT = 'static'
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'
我已经完成了 collectstatic
,一切运行正常。现在我服务器上的静态文件夹包含所有文件。
Nginx的:
我在使用 nginx 时遇到了问题,因为我改了一个名字, sites_available
然后开始出现错误,所以我重新安装了它,现在从日志来看一切都正常:
nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset:>
Active: active (running) since Wed 2024-05-01 14:47:13 UTC; 11min ago
Docs: man:nginx(8)
Process: 6843 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_proce>
Process: 6844 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (c>
Main PID: 6845 (nginx)
Tasks: 2 (limit: 1026)
Memory: 3.1M
CPU: 60ms
CGroup: /system.slice/nginx.service
6845 "nginx: master process /usr/sbin/nginx -g daemon on; master>
6846 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "">
May 01 14:47:13 23210 systemd[1]: nginx.service: Deactivated successfully.
May 01 14:47:13 23210 systemd[1]: Stopped A high performance web server and a r>
May 01 14:47:13 23210 systemd[1]: Starting A high performance web server and a >
May 01 14:47:13 23210 systemd[1]: Started A high performance web server and a r>
~
~
~
~
~
~
ESCOC
server and a reverse proxy server
/nginx.service; enabled; vendor preset: enabled)
2024-05-01 14:47:13 UTC; 11min ago
/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
inx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
ss /usr/sbin/nginx -g daemon on; master_process on;"
ss" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >
service: Deactivated successfully.
d A high performance web server and a reverse proxy server.
ng A high performance web server and a reverse proxy server...
d A high performance web server and a reverse proxy server.
~
~
~
~
~
~
ESCOD
nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset:>
Active: active (running) since Wed 2024-05-01 14:47:13 UTC; 11min ago
Docs: man:nginx(8)
Process: 6843 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_proce>
Process: 6844 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (c>
Main PID: 6845 (nginx)
Tasks: 2 (limit: 1026)
Memory: 3.1M
CPU: 60ms
CGroup: /system.slice/nginx.service
6845 "nginx: master process /usr/sbin/nginx -g daemon on; master>
6846 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "">
May 01 14:47:13 23210 systemd[1]: nginx.service: Deactivated successfully.
May 01 14:47:13 23210 systemd[1]: Stopped A high performance web server and a r>
May 01 14:47:13 23210 systemd[1]: Starting A high performance web server and a >
May 01 14:47:13 23210 systemd[1]: Started A high performance web server and a r>
~
~
~
~
~
~
lines 1-18/18 (END)
[2]+ Stopped systemctl status nginx
^Z
但我不知道为什么会出现错误。
Nginx 配置:
server {
listen 80;
server_name 77.777.77.77;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/ubuntu/portfolio-server;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
TL;DR: 复制第一个代码块
虽然在提出这个问题时这也许是不可能的,但我在寻找可以简单复制粘贴的解决方案时遇到了这个问题。 TypeScript 4.1 为我们提供了模板文字 ,使此实现成为可能。
TypeScript 游乐场的完整示例在 这里 .
首先,我们需要定义一些实用类型来自动为对象类型添加前缀。这可以通过以下代码块完成。如果你还不熟悉它们,我建议你先阅读 模板文字 and conditional 类型,它们在下面的代码中都大量使用
type addPrefix<TKey, TPrefix extends string> = TKey extends string
? `${TPrefix}${TKey}`
: never;
type removePrefix<TPrefixedKey, TPrefix extends string> = TPrefixedKey extends addPrefix<infer TKey, TPrefix>
? TKey
: '';
type prefixedValue<TObject extends object, TPrefixedKey extends string, TPrefix extends string> = TObject extends {[K in removePrefix<TPrefixedKey, TPrefix>]: infer TValue}
? TValue
: never;
type addPrefixToObject<TObject extends object, TPrefix extends string> = {
[K in addPrefix<keyof TObject, TPrefix>]: prefixedValue<TObject, K, TPrefix>
}
addPrefix
接受现有的 TKey
其 TPrefix
添加 TKey
扩展了类型字符串。如果它不扩展类型, string
, never
则返回类型。
removePrefix
接收 a TPrefixedKey
和 a TPrefix
从密钥中 TPrefix
删除, infer
以检索用于创建 TPrefixedKey
.
prefixedValue
接受一个 TObject
没有 的 。然后,它会 TValue
从 TPrefixedKey
使用 删除前缀后 removePrefix
。如果成功,则 TValue
返回 。否则,将返回一个空字符串,这仍然是一个有效的对象签名。
addPrefixToObject
将以上所有内容放在一起。它映射当前内部的所有键 TObject
并为其添加前缀。使用以下方法检索值 prefixedValue
.
如果你把它付诸行动,它似乎会发挥很好的作用:
const myConfig: OptionsConfig = {};
// Works:
myConfig.attr1 = {name: 'name'};
myConfig.attr2 = {"@parts": 1};
myConfig.attr3 = {"@parts": 1, name: 'name'};
// Error: Type '{ parts: number; }' is not assignable to type 'OptionsA | addPrefixToObject<OptionsB, "@">'.
myConfig.attr4 = {"parts": 1};
// Prints as:
// type prefixedOptionB = {
// "@parts": number;
// }
type PrefixedOptionB = addPrefixToObject<OptionsB, '@'>;
自动完成功能也正常运行:
所有这些可能都可以进一步优化,因此如果您有任何建议,请发表评论。
TypeScript 游乐场的完整示例在 这里 .