django-tables2 icon indicating copy to clipboard operation
django-tables2 copied to clipboard

CSRF with render_foo

Open MBfromOK opened this issue 5 years ago • 2 comments

First off, my apologies if this is my error... I am new to django and django_tables2 and trying really hard...

The Project:

I am building an intranet app that pulls data from multiple sources, adds them to the db, then lists them using a searchable, sortable table

Environment:

Python (venv) 3.8.2 Django: 2.2.12 Django-tables2: 2.3.1

The Goal:

  • A bootstrap 4 (ish) styled table displaying a searchable & sortable list of data.
  • A clickable "link" listed under the data for column 3 using a render_foo()
    • Clicking will call a python function
    • Function will return a pass / fail
    • Currently using a button styled like a link
    • Status returned eventually as a JS alert instead of loading a new page

What is working:

- A bootstrap 4 (ish) styled table
- A clickable "link" listed under the data for column 3 using a render_foo()

What isn't working:

- When I click the link I get a 403 forbidden error 
- I added the following to my html after the render_table: 
    ```            csrftoken: {{ csrftoken }}<br>
                   csrf_token: {{ csrf_token }}
    ```
-  I added code to my button to set the csrftoken as a tooltip for the link
- When compared they look like this:
    - html:    ```Ldjjb8kjcGP3Y``` 
    - button:    ```yBqUw5ySKSxs``` 

Questions / Thoughts:

  1. Am I overcomplicating this?
  2. Is there a simple way to fix this?
  3. Is there a way to pass the csrf during render?
  4. Looking at the tutorial & example scripts it seems to work fine, but I don't see any render_foo examples?

#Edits:

  • Complete re-write.

MBfromOK avatar May 12 '20 16:05 MBfromOK

On second thought... cleaning this up causes less clutter

Code pastebin coming next.

MBfromOK avatar May 24 '20 00:05 MBfromOK

Code pastebin: https://bpa.st/NB2Q

If anyone is willing to help me troubleshoot hit me up on discord: Compugician#1371

MBfromOK avatar May 25 '20 19:05 MBfromOK

This is an issue tracker to report bugs and request features, not a place to ask for help on using the library. Please use stackoverflow and tag your question with django-tables2

jieter avatar Dec 27 '22 07:12 jieter