Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Depends on Jinja2? #24

Closed
kezabelle opened this issue Dec 20, 2021 · 3 comments · Fixed by #25
Closed

Depends on Jinja2? #24

kezabelle opened this issue Dec 20, 2021 · 3 comments · Fixed by #25

Comments

@kezabelle
Copy link

Python Version

3.9.5

Django Version

4.0

Package Version

main

Description

Hey Adam,
Saw this on your blog (via the Django subreddit) and came here to see how you'd ended up doing things - mostly to see how you'd solved some of the thorny issues related to cancelling the SSE's WSGI request on client hang-up (because I have a similar package and I had to do some hacks!) ... and actually I don't know how in the world you've done it, but done it you have, kudos (I'd love to know which bit is solving it, if you're feeling generous at any point)

Anyway, trying to set it up to explore the hang-up situation, I encountered the following exception:

File "/path/.direnv/python-3.9.5/lib/python3.9/site-packages/django/utils/autoreload.py", line 644, in run_with_reloader
    start_django(reloader, main_func, *args, **kwargs)
  File "/path/.direnv/python-3.9.5/lib/python3.9/site-packages/django/utils/autoreload.py", line 629, in start_django
    reloader.run(django_main_thread)
  File "/path/.direnv/python-3.9.5/lib/python3.9/site-packages/django/utils/autoreload.py", line 334, in run
    autoreload_started.send(sender=self)
  File "/path/.direnv/python-3.9.5/lib/python3.9/site-packages/django/dispatch/dispatcher.py", line 170, in send
    return [
  File "/path/.direnv/python-3.9.5/lib/python3.9/site-packages/django/dispatch/dispatcher.py", line 171, in <listcomp>
    (receiver, receiver(signal=self, sender=sender, **named))
  File "/path/.direnv/python-3.9.5/src/django-browser-reload/src/django_browser_reload/views.py", line 62, in on_autoreload_started
    for directory in jinja_template_directories():
  File "/path/.direnv/python-3.9.5/src/django-browser-reload/src/django_browser_reload/views.py", line 41, in jinja_template_directories
    from django.template.backends.jinja2 import Jinja2
  File "/path/.direnv/python-3.9.5/lib/python3.9/site-packages/django/template/backends/jinja2.py", line 3, in <module>
      import jinja2
ModuleNotFoundError: No module named 'jinja2'

Naturally it's easy enough to resolve (installed jinja2), but thought you might want to know.

@adamchainz
Copy link
Owner

Saw this on your blog (via the Django subreddit) and came here to see how you'd ended up doing things - mostly to see how you'd solved some of the thorny issues related to cancelling the SSE's WSGI request on client hang-up (because I have a similar package and I had to do some hacks!) ... and actually I don't know how in the world you've done it, but done it you have, kudos (I'd love to know which bit is solving it, if you're feeling generous at any point)

Oh cool, I hadn't seen your package! Nice that you have the livereload logic to replace things like CSS. Perhaps I will try add that here.

I haven't done anything special to handle connection closing. Perhaps my package's use of a SharedWorker makes the hangup slightly cleaner? Or perhaps I actually have the same issue as you did.

Naturally it's easy enough to resolve (installed jinja2), but thought you might want to know.

Ah very good point - I need to make that a cautious import. I have an idea how.

@kezabelle
Copy link
Author

Perhaps my package's use of a SharedWorker makes the hangup slightly cleaner? Or perhaps I actually have the same issue as you did.

A cursory glance at the SSE view suggests you don't have the same issue, hence the kudos and head-scratching. Apologies if I wasn't clear enough! The simple test I did was to generate a new uuid4() within the view, and then print that repeatedly within the while True loop of the inner generator. After closing down a tab or refreshing, I only saw the old UUID appear a maximum of twice before dropping entirely (with a new UUID taking its place). I'd guess it's maybe to do with the shared worker, but I've not figured out the how or why. Impressive though; I'm envious ;)

Nice that you have the livereload logic to replace things like CSS. Perhaps I will try add that here.

Yeah there's a few niceties I added as I got further in and frustrated by the reloads themselves. That idea specifically comes from Phoenix, but another one you may end up finding yourself wanting is persistence of form data/scroll position/focus'd element, of debouncing multiple changes into one when the tab isn't active. YMMV.

@adamchainz
Copy link
Owner

Yeah there's a few niceties I added as I got further in and frustrated by the reloads themselves. That idea specifically comes from Phoenix, but another one you may end up finding yourself wanting is persistence of form data/scroll position/focus'd element, of debouncing multiple changes into one when the tab isn't active. YMMV.

Yeah those sound nice. Right now I just want to do the simplest thing that works, most of the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants