{"id":956,"date":"2025-11-04T10:44:27","date_gmt":"2025-11-04T10:44:27","guid":{"rendered":"https:\/\/tensorzen.blog\/?p=956"},"modified":"2025-11-04T10:44:27","modified_gmt":"2025-11-04T10:44:27","slug":"django%e9%83%a8%e7%bd%b2%e9%9d%99%e6%80%81%e6%96%87%e4%bb%b6%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/tensorzen.blog\/?p=956","title":{"rendered":"Django\u90e8\u7f72\u9759\u6001\u6587\u4ef6\u95ee\u9898"},"content":{"rendered":"\n<p>\u767b\u9646\u4e00\u4e2aDjango\u670d\u52a1\u5668\u7684admin\u9875\u9762\u7684\u65f6\u5019\u51fa\u73b0\u5982\u4e0b\u9519\u8bef\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"471\" src=\"https:\/\/tensorzen.blog\/wp-content\/uploads\/2025\/11\/image-1024x471.png\" alt=\"\" class=\"wp-image-957\" srcset=\"https:\/\/tensorzen.blog\/wp-content\/uploads\/2025\/11\/image-1024x471.png 1024w, https:\/\/tensorzen.blog\/wp-content\/uploads\/2025\/11\/image-300x138.png 300w, https:\/\/tensorzen.blog\/wp-content\/uploads\/2025\/11\/image-768x353.png 768w, https:\/\/tensorzen.blog\/wp-content\/uploads\/2025\/11\/image.png 1500w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u4e3b\u8981\u539f\u56e0\u662f\u6ca1\u6709\u628aadmin\u7684\u9759\u6001\u6587\u4ef6\u5199\u5165\u5230domain\/static\u5bf9\u5e94\u7684\u6587\u4ef6\u91cc<\/p>\n\n\n\n<p>\u5728setting.py\u4e2d\u914d\u7f6e:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Static files (CSS, JavaScript, Images)\n# https:\/\/docs.djangoproject.com\/en\/4.2\/howto\/static-files\/\n\nSTATIC_URL = 'static\/'\nSTATIC_ROOT = BASE_DIR \/ 'staticfiles'<\/code><\/pre>\n\n\n\n<p>\u8fd9\u91cc\u8bbe\u7f6e\u7684STATIC_ROOT\u662f\u670d\u52a1\u5668\u672c\u5730\u76ee\u5f55\uff0c\u751f\u6210\u7684\u9759\u6001\u6587\u4ef6\u4f1a\u653e\u5728\u8fd9\u91cc\u9762\u3002\u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python manage.py collectstatic<\/code><\/pre>\n\n\n\n<p>\u6267\u884c\u5b8c\u4e86\uff0c\u4f1a\u751f\u6210\u4e00\u4e9b\u9759\u6001\u6587\u4ef6\uff0c\u5927\u6982\u50cf\u8fd9\u6837\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>161 static files copied to '\/web\/backend\/staticfiles'.<\/code><\/pre>\n\n\n\n<p>\u914d\u7f6eNginx\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>server {\n    listen 80;\n    server_name dict.tensorzen.blog;\n\n    location \/static\/ {\n        alias \/path\/to\/your\/project\/staticfiles\/;\n    }\n\n    location \/ {\n        proxy_pass http:\/\/127.0.0.1:8000;\n        proxy_set_header Host $host;\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u91cd\u542f\u4e00\u4e0bnginx\u5c31\u53ef\u4ee5\u4e86<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart nginx<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u767b\u9646\u4e00\u4e2aDjango\u670d\u52a1\u5668\u7684admin\u9875\u9762\u7684\u65f6\u5019\u51fa\u73b0\u5982\u4e0b\u9519\u8bef\uff1a \u4e3b\u8981\u539f\u56e0\u662f\u6ca1\u6709\u628aadmin\u7684\u9759\u6001\u6587\u4ef6\u5199\u5165\u5230domain\/static\u5bf9\u5e94\u7684\u6587\u4ef6\u91cc \u5728setting.py\u4e2d\u914d\u7f6e: \u8fd9\u91cc\u8bbe\u7f6e\u7684STATIC_ROOT\u662f\u670d\u52a1\u5668\u672c\u5730\u76ee\u5f55\uff0c\u751f\u6210\u7684\u9759\u6001\u6587\u4ef6\u4f1a\u653e\u5728\u8fd9\u91cc\u9762\u3002\u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff1a \u6267\u884c\u5b8c\u4e86\uff0c\u4f1a\u751f\u6210\u4e00\u4e9b\u9759\u6001\u6587\u4ef6\uff0c\u5927\u6982\u50cf\u8fd9\u6837\uff1a \u914d\u7f6eNginx\uff1a \u91cd\u542f\u4e00\u4e0bnginx\u5c31\u53ef\u4ee5\u4e86<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-956","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/tensorzen.blog\/index.php?rest_route=\/wp\/v2\/posts\/956","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tensorzen.blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tensorzen.blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tensorzen.blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tensorzen.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=956"}],"version-history":[{"count":1,"href":"https:\/\/tensorzen.blog\/index.php?rest_route=\/wp\/v2\/posts\/956\/revisions"}],"predecessor-version":[{"id":958,"href":"https:\/\/tensorzen.blog\/index.php?rest_route=\/wp\/v2\/posts\/956\/revisions\/958"}],"wp:attachment":[{"href":"https:\/\/tensorzen.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=956"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tensorzen.blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=956"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tensorzen.blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=956"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}