codelv / enaml-web

Build interactive websites with enaml
https://codelv.com/projects/enaml-web/
MIT License
99 stars 17 forks source link

Enaml-web and Django #27

Closed youpsla closed 1 year ago

youpsla commented 3 years ago

Hello, I'll have to create a project. I'm hesitating using enaml-web with Django. Enaml-web is so fun !!

I have seen the question has already been asked #8. You have answered

Yes. You can create a LxmlApplication which has no server component and then render pages for any application (django, flask, etc..) or save them to a file to make a static site.

You talked about LxmlApplication. Haven't see any code relating to that in master.

Could you give me some hints and how to do this coupling ?

Regards

youpsla commented 3 years ago

Not enough clear. I'll reopen it later with better explained question(s).

frmdstryr commented 3 years ago

Using view.render() returns a string so you should be able to just use it like any other response in django.

import enaml
from django.http import HttpResponse

with enaml.imports():
   from views import IndexView

def index(request):
    view = IndexView(request=request)
    return HttpResponse(view.render())
youpsla commented 3 years ago

As usual great answer. Thanks a lots. I'll give it a try next week.

danieljfarrell commented 3 years ago

@youpsla just wondering if you have a Hello World example that uses Django and Enaml?

youpsla commented 3 years ago

Hello @danieljfarrell . haven't had time to do it (new job !!!). When I have spare time, will be my first task.....

danieljfarrell commented 3 years ago

That would be great!

youpsla commented 1 year ago
with enaml.imports():
   from views import IndexView

Hi. It's a long time ....

Tried the solution in a docker container. Got an issue with

with enaml.imports():
   from views import IndexView

It raise an import error.

My views file is a file named views.enaml, it's an enaml file not a py one.

I tried to deep in EnamlImporter but didn't understood enough.

Any idea ?

youpsla commented 1 year ago

Found the solution. Just had to add a dot for relative import:

with enaml.imports():
   from .views import IndexView