Django apache2 url прямой без базового URL - PullRequest
0 голосов
/ 27 июня 2018

Я установил проект Djagno на Apache, и он работал очень хорошо. Но после того, как я установил базовый 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. Как я могу решить эту проблему. Должен ли я изменить все URL в html-страницах с помощью base_url?

1 Ответ

0 голосов
/ 27 июня 2018

Вы вообще не должны жестко кодировать URL в шаблонах. Используйте тег {% url %}, который среди прочего будет учитывать префикс URL.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...