当在apache服务器上查看时,我的django管理页面没有css。

时间:2022-10-06 10:03:46

I just finished to serve my pages on the internet through apache. I can see my webpage nicely, but when I try the admin, the django admin page don't have the css with it, just the html page. But my webpage's css are displaying nicely. Thank you!

我刚刚完成了通过apache在internet上的页面服务。我可以很好地看到我的网页,但是当我尝试管理时,django管理页面没有css,只有html页面。但是我的网页的css显示得很好。谢谢你!

my http.conf snippet:

我的http。参看片段:

WSGIPythonPath C:/Users/robin/web/etc/etc

<Directory C:/Users/robin/web/etc/etc>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>

#Alias /robots.txt /path/to/mysite.com/static/robots.txt
#Alias /favicon.ico /path/to/mysite.com/static/favicon.ico

AliasMatch ^/([^/]*\.css) C:/Users/robin/web/etc/etc/static/styles/$1

#Alias /media/ /path/to/mysite.com/media/
Alias /static/ C:/Users/robin/web/etc/etc/static/

<Directory C:/Users/robin/web/etc/etc/static>
Order deny,allow
Allow from all
</Directory>

#<Directory /path/to/mysite.com/media>
#Order deny,allow
#Allow from all
#</Directory>

WSGIScriptAlias / C:/Users/robin/web/etc/etc/etc/wsgi.py

<Directory C:/Users/robin/web/etc/etc/etc>
<Files wsgi.py>
Order allow,deny
Allow from all
</Files>
</Directory>

my settings snippet:

我的设置代码片段:

STATIC_ROOT = 'C:/Users/robin/web/etc/static/'
STATIC_URL = '/static/'

I have made a different directory for the static, and have already directed django to the dir where to find static. I have edited and added the setting's snippet above, kindly check it. And have run the collectstatic command, and it has created three directories - admin, css and images. And copied all the statics from the project to that directory, even the admin's css and images in the admin dir. And the server is also displaying my project's css nicely. But not of the admin's css. What am I missing? Please guide me.

我为静态创建了一个不同的目录,并且已经将django定向到要查找静态的目录。我已经编辑并添加了上面的设置片段,请检查。并运行了collectstatic命令,它创建了三个目录——admin、css和images。并将项目中的所有静态数据复制到该目录中,甚至是管理员的css和admin目录中的图像。服务器也很好地显示了我的项目的css。但不是管理员的css。我缺少什么?请指导我。

2 个解决方案

#1


3  

Each application has own static files (generally in 'static' directory, but not necessarily, see settings.STATICFILES_FINDERS). Django serves this files in debug mode, but before deploy to real server you must collect all static from all apps, put it into one folder and configure webserver. You can do it manually, or set settings.STATIC_ROOT to apache's docroot and run collectstatic command.

每个应用程序都有自己的静态文件(通常在“静态”目录中,但不一定,请参阅settings.STATICFILES_FINDERS)。Django提供了调试模式下的文件,但在部署到真正的服务器之前,您必须从所有应用程序中收集所有的静态文件,将其放入一个文件夹并配置webserver。你可以手动操作,或者设置设置。静态根到apache的docroot并运行collectstatic命令。

In sum, apache config:

总之,apache配置:

Alias /static/ C:/Users/robin/web/etc/etc/static/

settings.py:

settings.py:

STATIC_ROOT = 'C:/Users/robin/web/etc/etc/static/'

And run collectstatic:

和运行collectstatic:

python manage.py collectstatic

#2


2  

Tell Django where to find the static files (if you have not already).

告诉Django在哪里找到静态文件(如果还没有的话)。

First, make sure you have STATIC_ROOT and STATIC_URL set correctly in `settings.py', and then on your live server simply run the following command.

首先,确保在“设置”中正确设置了STATIC_ROOT和STATIC_URL。然后在您的live服务器上运行以下命令。

python manage.py collectstatic

This will collect all static files necessary for the admin to render correctly.

这将收集管理员正确呈现所需的所有静态文件。

When running the development server (runserver) static files are automatically found using STATICFILES_FINDERS, but in production this is not the case, in-fact STATICFILES_FINDERS does somethine else in production, it finds and collects the files after `running python manage.py collectstatic ' they are then served in your case by Apache.

当运行开发服务器(runserver)静态文件时,会使用STATICFILES_FINDERS自动找到,但在生产环境中不是这样的,实际上,STATICFILES_FINDERS在生产环境中做一些其他的事情,它会在“运行python管理”之后找到并收集文件。py collectstatic“然后它们由Apache在您的案例中提供服务。

#1


3  

Each application has own static files (generally in 'static' directory, but not necessarily, see settings.STATICFILES_FINDERS). Django serves this files in debug mode, but before deploy to real server you must collect all static from all apps, put it into one folder and configure webserver. You can do it manually, or set settings.STATIC_ROOT to apache's docroot and run collectstatic command.

每个应用程序都有自己的静态文件(通常在“静态”目录中,但不一定,请参阅settings.STATICFILES_FINDERS)。Django提供了调试模式下的文件,但在部署到真正的服务器之前,您必须从所有应用程序中收集所有的静态文件,将其放入一个文件夹并配置webserver。你可以手动操作,或者设置设置。静态根到apache的docroot并运行collectstatic命令。

In sum, apache config:

总之,apache配置:

Alias /static/ C:/Users/robin/web/etc/etc/static/

settings.py:

settings.py:

STATIC_ROOT = 'C:/Users/robin/web/etc/etc/static/'

And run collectstatic:

和运行collectstatic:

python manage.py collectstatic

#2


2  

Tell Django where to find the static files (if you have not already).

告诉Django在哪里找到静态文件(如果还没有的话)。

First, make sure you have STATIC_ROOT and STATIC_URL set correctly in `settings.py', and then on your live server simply run the following command.

首先,确保在“设置”中正确设置了STATIC_ROOT和STATIC_URL。然后在您的live服务器上运行以下命令。

python manage.py collectstatic

This will collect all static files necessary for the admin to render correctly.

这将收集管理员正确呈现所需的所有静态文件。

When running the development server (runserver) static files are automatically found using STATICFILES_FINDERS, but in production this is not the case, in-fact STATICFILES_FINDERS does somethine else in production, it finds and collects the files after `running python manage.py collectstatic ' they are then served in your case by Apache.

当运行开发服务器(runserver)静态文件时,会使用STATICFILES_FINDERS自动找到,但在生产环境中不是这样的,实际上,STATICFILES_FINDERS在生产环境中做一些其他的事情,它会在“运行python管理”之后找到并收集文件。py collectstatic“然后它们由Apache在您的案例中提供服务。