Note that there are some explanatory texts on larger screens.

plurals
  1. POimplementing a template tag within a generic app - django
    text
    copied!<p>I have developed some code that builds on the contrib comments app, such as handlers for ajax requests. This code is in a separate application, which we can call 'comments2'. the url configuration of the project is structured in such a way that all calls to /comments are directed to this app's views. This works without problems.</p> <p>Very recently I made a new page that shows comments flagged as inappropriate.</p> <p>I conceived that it was best done by writing an inclusion templatetag, and wrote one. It works like this:</p> <pre><code>{% display_flagged_comments 'market' %} </code></pre> <p>This tag is placed inside the main app's relevant template.</p> <p>As seen in the code above, I pass what model (<strong>Market</strong> in this case) the comments belongs to so that the comments2 app remains generic. </p> <p>I have three issues here that I need guidance on:</p> <p>First, I feel that the model argument being inside quotes (<strong>'market'</strong>) make the code somewhat less elegant. In the code the argument is converted to a model:</p> <pre><code>#template tag def show_comments(modelname): model = ContentType.objects.get(model=modelname) ... # get comments and return them </code></pre> <p>Second, since all requests with <strong>/comments</strong> are directed to comment2 app, I need to devise a different url for this page (it sits inside the main app), such as /managecomments. I find doing that also inelegant.</p> <p>Third, I want to know if I followed a correct path or is there a better way to implement what I'm trying to do.</p> <p>Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload