0

Django template not loading from DB

I'm in the process of changing the templates to a new design. During this process, the category list stopped loading.

“category_list takes 2 arguments”

In the html file, “category_list” is being loaded with:

{% category_list request.path %}

Can someone explain what it means by “takes 2 arguments” in this situation?

Edit: Here is the custom template tag:

def category_list(request_path):
    list_cache_key = 'active_category_link_list'
    active_categories = cache.get(list_cache_key)
    if not active_categories:
        active_categories = Category.active.all()
        cache.set(list_cache_key, active_categories, CACHE_TIMEOUT)
    return {
        'active_categories': active_categories,
        'request_path': request_path
    }
pythondjango
  • 1,561
  • 2
  • 13
  • 23

1 Answers1

0

category_list must be a Django custom template tag that takes two arguments.

In your current template syntax your first argument is request.path. Look in your code for the definition of function category_list and check what arguments it should receive and add the second argument.

Joseph Victor Zammit
  • 14,760
  • 10
  • 76
  • 102
  • I've added the template tag definition. It looks like it's returning 2 arguments. – pythondjango Oct 06 '12 at 17:44
  • @pythondjango It's returning 1 argument; a dict with two keys `active_categories` and `request_path`. Can you post the full exception traceback? – Joseph Victor Zammit Oct 06 '12 at 17:45
  • it returns two, but it gets 1 `request_path` - just add `*args, **kwargs` and check with a `print` command what you get from `request.path` – Thomas Schwärzl Oct 06 '12 at 17:47
  • Added *args, **kwargs but same issue. Everything was working yesterday and no .py code was changed, only the templates. Doesn't that mean it's a template issue? – pythondjango Oct 06 '12 at 17:59
  • where did you add *args and **kwargs ? – Thomas Schwärzl Oct 06 '12 at 18:01
  • the category_list definition posted above. def category_list(request_path, *args, **kwargs): – pythondjango Oct 06 '12 at 18:03
  • ok - now have a look at this ( http://stackoverflow.com/a/3394898/1073606 ). Just `print` your args and kwargs to see in developementserver `python manage.py runserver` what `request.path` is sending to your function – Thomas Schwärzl Oct 06 '12 at 18:07
  • @init3 I'm interacting with a web server with apache. I'm not sure how to print what you're asking. – pythondjango Oct 06 '12 at 18:29
  • just connect via ssh to your webserver. Change to the directory of your project and run `python manage.py runserver :8000` then browse to the ip like `http://1.1.1.1:8000`. You'll get the same error, but you will see the output of `print` in your ssh-console – Thomas Schwärzl Oct 06 '12 at 18:37
  • 1
    The issue was there was extra markup that I found was screwing with everything in the definition. I deleted that and poof. No more errors. Thanks guys, you got me on the right track. – pythondjango Oct 06 '12 at 18:57