0

I have installed on Djagno project on Apache and it was working very well. But after I set the base url of the projects, it breaks things.

<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. How can I fix this problem. Should I change the all urls in html pages with base_url?

1 Answer 1

2

You shouldn't be hard-coding URLs in templates at all. Use the {% url %} tag, which among things will take the URL prefix into account.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.