[英]Django apache2 url direct with no base url
I have installed on Djagno project on Apache and it was working very well. 我已经在Apache的Djagno项目上安装了它,并且运行得很好。 But after I set the base url of the projects, it breaks things. 但是,在我设置了项目的基本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
it's working fine. 工作正常。 The problem is that. 问题是。
<a href="/all">All</a>
When I click the link All
is should direct to /base_url/all
, but it goes to /all
, so I had to manually type /base_url
. 当我单击链接All
,应直接指向/base_url/all
,但应转到/all
,因此我不得不手动输入/base_url
。 How can I fix this problem. 我该如何解决此问题。 Should I change the all urls in html pages with base_url
? 我应该使用base_url
更改html页面中的所有url吗?
You shouldn't be hard-coding URLs in templates at all. 您根本不应该在模板中对URL进行硬编码。 Use the {% url %}
tag, which among things will take the URL prefix into account. 使用{% url %}
标记,其中将考虑URL前缀。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.