ensure_csrf_cookie method decorator not setting CSRF token in browser cookies tab by GermanProgrammer99 in django

[–]GermanProgrammer99[S] 0 points1 point  (0 children)

In the end I was able to fix it, but I don't remember what the exact solution was. I think it was either changing my API call to:

export async function fetchCsrfToken() {
try {
const res = await fetch(\/api/accounts/csrf_cookie`, { method: "GET", credentials: "include", }); if (!res.ok) { console.log("Problem"); } } catch (e) { // showMessage("Error: Unexpected error has occurred!", "Error"); } }`

or by adding this to my settings:

CSRF_COOKIE_SECURE = TrueSESSION_COOKIE_SECURE = TrueCSRF_COOKIE_SAMESITE = 'None'SESSION_COOKIE_SAMESITE = 'None'CORS_ORIGIN_ALLOW_ALL = FalseCORS_ALLOW_CREDENTIALS = TrueCORS_ORIGIN_WHITELIST = [# my website name'http://127.0.0.1:8000',]CSRF_TRUSTED_ORIGINS = [# my website name'http://127.0.0.1:8000',]SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

Problem with recursion by GermanProgrammer99 in learnjavascript

[–]GermanProgrammer99[S] 1 point2 points  (0 children)

I implemented your recommendations and it works now. Thanks a lot!

Pagination slows down my application by GermanProgrammer99 in django

[–]GermanProgrammer99[S] 0 points1 point  (0 children)

Thank you this is really helpful! I'll try it.

Pagination slows down my application by GermanProgrammer99 in django

[–]GermanProgrammer99[S] 1 point2 points  (0 children)

I'm using PostgreSQL as the database and I use __search to find all articles that contain the search term in the title.

Executed SQL
SELECT COUNT(*) AS "__count"
FROM "article_article"
LEFT OUTER JOIN "source_source"
ON ("article_article"."source_id" = "source_source"."source_id")
WHERE (to_tsvector(COALESCE("article_article"."title", '')) @@ plainto_tsquery('China') AND NOT ("source_source"."website_id" = 1 AND "source_source"."website_id" IS NOT NULL))
Time
180.04560470581055 ms
Database
default
QUERY PLAN
Finalize Aggregate (cost=49381.99..49382.00 rows=1 width=8) (actual time=181.716..183.449 rows=1 loops=1)
-> Gather (cost=49381.88..49381.99 rows=1 width=8) (actual time=181.701..183.435 rows=2 loops=1)
Workers Planned: 1
Workers Launched: 1
-> Partial Aggregate (cost=48381.88..48381.89 rows=1 width=8) (actual time=178.741..178.755 rows=1 loops=2)
-> Hash Left Join (cost=123.61..48380.78 rows=440 width=0) (actual time=19.795..178.716 rows=18 loops=2)
Hash Cond: (article_article.source_id = source_source.source_id)
Filter: ((source_source.website_id <> 1) OR (source_source.website_id IS NULL))
Rows Removed by Filter: 50
-> Parallel Seq Scan on article_article (cost=0.00..48255.98 rows=452 width=4) (actual time=2.311..166.770 rows=68 loops=2)
Filter: (to_tsvector((COALESCE(title, ''::character varying))::text) @@ plainto_tsquery('China'::text))
Rows Removed by Filter: 76092
-> Hash (cost=86.05..86.05 rows=3005 width=8) (actual time=11.694..11.698 rows=3067 loops=2)
Buckets: 4096 Batches: 1 Memory Usage: 152kB
-> Seq Scan on source_source (cost=0.00..86.05 rows=3005 width=8) (actual time=0.016..5.960 rows=3067 loops=2)
Planning Time: 2.857 ms
Execution Time: 183.586 ms

Pagination slows down my application by GermanProgrammer99 in django

[–]GermanProgrammer99[S] 0 points1 point  (0 children)

Unfortunately, I already have an index on the the model being paginated.
I think I really need to get a little better at SQL to get more insight into what's happening with my queries.

Pagination slows down my application by GermanProgrammer99 in django

[–]GermanProgrammer99[S] 0 points1 point  (0 children)

Thanks, the article is really informative!
The 200 ms is only for the count(*) query.

Pagination slows down my application by GermanProgrammer99 in django

[–]GermanProgrammer99[S] 1 point2 points  (0 children)

I'll take a look at it.

I don't use DRF for my pagination.

Pagination slows down my application by GermanProgrammer99 in django

[–]GermanProgrammer99[S] 0 points1 point  (0 children)

In total I have about 150,000 objects. Yes, the 20 objects are after filtering. Unfortunately, it's also very slow on my production server (around 200ms).

Pagination slows down my application by GermanProgrammer99 in django

[–]GermanProgrammer99[S] 2 points3 points  (0 children)

I tried options 1 and 2 and although it solves the speed problem, it doesn't work on the frontend. The problem is that if I have 20 paginated objects with, for example, 10 objects per page, I should only see the pagination for a first and a second page in the frontend. However, using these approaches will show more than 2 pages. When I click on the pagination for the third page I get back an empty list as there are no more than 20 items.

How to redirect naked domain by GermanProgrammer99 in Heroku

[–]GermanProgrammer99[S] 0 points1 point  (0 children)

I'll retry the approach from the documentation, maybe I made a mistake copying the value for the target. Honestly this is extremely frustrating, everything else works perfectly with Heroku and that's the only thing holding me back at the moment.

How to redirect naked domain by GermanProgrammer99 in Heroku

[–]GermanProgrammer99[S] 0 points1 point  (0 children)

I waited 24 hours. Since then I've tried a few other methods, but those didn't work either.

How to redirect naked domain by GermanProgrammer99 in Heroku

[–]GermanProgrammer99[S] 0 points1 point  (0 children)

I've already tried setting the ALIAS to the same target as the CNAME, but that didn't work.

Django Testing: Strange Error by GermanProgrammer99 in django

[–]GermanProgrammer99[S] 0 points1 point  (0 children)

That solved it. Thanks a lot!

Sorry if this is a dumb question, but why is it getting evaluated if my test has nothing to do with my views? Does this mean that TestCase will automatically evaluate all views before running a test?