Search code examples
djangodjango-hosts

How to convert Template tags from normal django to the one django-hosts use


I have just added django-hosts to setup subdomains for my site which works perfectly. Next step is just to convert all the normal django URL's in my template to the one django-hosts like.

I know how to link pages , but once I need to add variables to my URL's i'm not sure how to construct the code for it.

Normal django URL that works

{% url 'golemstats:nodeinfo' node.Node_id node.Node|slugify %}

How do I convert that to a URL that django-hosts like? I've tried the following:

{% host_url 'nodeinfo' host 'golemstats' 'node.Node_id' 'node.Node|slugify' %}

hosts.py

from django.conf import settings
from django_hosts import patterns, host

host_patterns = patterns('',
    host(r'www', settings.ROOT_URLCONF, name='www'),
    host(r'golem', 'golemstats.urls', name='golemstats'),
)

golemstats.urls

from django.urls import path
from . import views

app_name = 'golemstats'

urlpatterns = [
    path('', views.index, name='index'),
    path('node', views.searchNode, name='searchNode'),
    path('node/<nodeid>/<node>', views.nodeinfo, name="nodeinfo"),
    path('version-notifier', views.notifierIndex, name="notifier"),
    path('ports', views.portScanner, name="portscanner"),
    path('scoreboard', views.scoreboard, name="scoreboard"),
    path('tools', views.tools, name="tools"),
    path('troubleshooting', views.troubleshooting, name="troubleshooting"),
    path('network', views.networkOverview, name="networkOverview"),
]

Solution

  • Fixed. have to put arguments after host_url

    {% host_url 'nodeinfo' node.Node_id node.Node|slugify host 'golemstats' %}