Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
Showing the line numbers in <pre> in Django project using Pygments

I'm using the Pygments package in my Django project. When I try to render the code snippet in my template, it renders the whole data as follows:

Template:
...
{% pygmentify %}
<pre class="{{snippet.lang}}">{{snippet.body}}</pre>
{% endpygmentify %}
...

Final rendered HTML:

<pre lang="python">
...
<span class="kn">import</span> <span class="nn">hello</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">'hey'</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">test</span><span class="p">():</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">'in the function'</span><span class="p">)</span>
...
</pre>

It actually works with no pain. The entire code block is being highlighted properly. The thing is that I want to show the line number as well. Should I style them or there is only a simple Pygments configuration needed?

Thanks.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you are using django-pygmentify, you can pass keyword arguments as indicated in their docs

{% pygmentify linenos='inline' %}
<pre class="{{snippet.lang}}">{{snippet.body}}</pre>
{% endpygmentify %}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!