我已经在Apache的Djagno项目上安装了它,并且运行良好。 但是,在我设置了项目的基本URL后,它破坏了事情。
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAlias www.mydomainname.com
Alias /static /path/to/project/static
<Directory /path/to/project/static>
Require all granted
</Directory>
<Directory /path/to/project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess projectname python-path=/var/bin/python3 python-home=/path/to/project
WSGIProcessGroup projectname
WSGIScriptAlias /base_url /path/to/project/wsgi.py
#Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog /path/to/project/error.log
#CustomLog ${APACHE_LOG_DIR}/access.log combined
CustomLog /path/to/project/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
工作正常。 问题是这样。
<a href="/all">All</a>
当我单击链接All
时,应直接指向/base_url/all
,但链接应转到/all
,因此我不得不手动键入/base_url
。
我该如何解决此问题。我是否应该使用base_url
更改html页面中的所有URL?
答案 0 :(得分:2)
您根本不应该在模板中对URL进行硬编码。使用{% url %}
标签,其中将考虑URL前缀。