Re: #cherrypy #tornado #sqlalchemy

vahid peivandy <[email protected]> Mon, 7 Jan 2019 09:35:10 +0330
Newsgroups gmane.comp.python.cherrypy
Message-ID <CAHZJq=5HCAgowh-RoaB9+VpGNkJiUbJ3AqJbfo=Xvr+xyCME=g@mail.gmail.com>
--000000000000284a38057ed8056f
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

thanks a lot

On Sun, Jan 6, 2019 at 5:58 PM Sviatoslav Sydorenko <[email protected]>
wrote:

> You shouldn't be mixing several web frameworks (especially not sync +
> async). I think you need to learn more about how the web works now (HTTP,
> html, templating, etc.)
>
> Regarding connecting SA to CherryPy, I've already sent you a repo with
> such app example. Essential parts are db plugin (
> https://github.com/Lawouach/Twiseless/blob/master/lib/plugin/db.py),
> db tool (https://github.com/Lawouach/Twiseless/blob/master/lib/tool/db.py=
)
> and models package (
> https://github.com/Lawouach/Twiseless/tree/master/lib/model).
>
> Other parts are important too, like this user tool
> https://github.com/Lawouach/Twiseless/blob/master/lib/tool/user.py#L30-L3=
2
> which retrieves a user from db shielding handlers from unauthorized acces=
s.
>
> You have to learn the concepts of your chosen framework and then learn ho=
w
> to operate them.
>
> For CherryPy the process is roughly:
> 1. Have HTTP handlers which are bound to URLs. CherryPy will then call
> them whenever incoming HTTP request matches URLs.
> 2. HTTP handlers should return HTML (in common case). Since you'll
> probably want to render it from templates instead of hardcoded strings
> you'll probably need to learn Jinja2 or similar.
> 3. Since you want to access DB you'll need to use a DB driver or an ORM
> (SQLAlchemy in your case). You'll want to separate it's initialization co=
de
> and put it into the plugin which will be your interface to the DB and wil=
l
> provide you a session object to work with it. Plugins are run in separate
> threads and are accessible via a publish-subscribe bus.
> 4. To make accessing DB session easier you add a db tool which binds the
> session to current request object so that it's accessible through somethi=
ng
> like `cherrypy.request.db`. Tools are callables executed at certain point=
s
> of request-response cycle, before and after request handler is called.
> 5. With those things above in place it's possible to access a db from
> handlers (IRL you might want to separate the logic part into its own enti=
ty
> as well).
>
> =D0=BD=D0=B4, 6 =D1=81=D1=96=D1=87. 2019 =D0=BE 14:51 vahid peivandy <tar=
[email protected]> =D0=BF=D0=B8=D1=88=D0=B5:
>
>> yes I write this tornado: https://paste.ubuntu.com/p/3kcj6ZRgFQ/
>> and now wanna connect this code: https://paste.ubuntu.com/p/BzmBTnrN54/
>> to tornado or cherrypy
>>
>> On Sat, Jan 5, 2019 at 4:43 AM Tim Roberts <[email protected]> wrote:
>>
>>> vahid peivandy wrote:
>>>
>>> I cannot connect mu db on web server tornado or web server cherrypy thi=
s
>>> is my problem and see this page but not help me
>>> https://tornado-sqlalchemy.readthedocs.io/en/latest/
>>>
>>> Have you ever done a web application of any kind before?  To me, it
>>> looks like you are trying to jump straight to the final steps of buildi=
ng a
>>> web app, when you haven't taken any of the early steps yet.  Don't take=
 on
>>> too many new things at once.  Can you make a basic Tornado or CherryPy
>>> application work?  You start by displaying the basic "hello world" page=
.
>>> Then you add a couple of very basic pages with buttons or links to flip
>>> back and forth between them.  Then you substitute in some of your own t=
ext,
>>> to prove you understand the templating scheme.  At that point, you'll b=
e
>>> more familiar with the framework, and the explanation on how to integra=
te
>>> SQLAlchemy will make more sense.
>>>
>>> No one here is going to write your application for you.  We can offer
>>> guidelines, and we can help you work through the problems you encounter=
,
>>> but you have to do the work.
>>>
>>> --
>>> Tim Roberts, [email protected]
>>> Providenza & Boekelheide, Inc.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "cherrypy-users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to cherrypy-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
>>> To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
>>> Visit this group at https://groups.google.com/group/cherrypy-users.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
>> You received this message because you are subscribed to the Google Group=
s
>> "cherrypy-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n
>> email to cherrypy-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
>> To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
>> Visit this group at https://groups.google.com/group/cherrypy-users.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> --
> Cheers,
> Sviatoslav.
>
> --
> You received this message because you are subscribed to the Google Groups
> "cherrypy-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cherrypy-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
> To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
> Visit this group at https://groups.google.com/group/cherrypy-users.
> For more options, visit https://groups.google.com/d/optout.
>

--=20
You received this message because you are subscribed to the Google Groups "=
cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to cherrypy-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.

--000000000000284a38057ed8056f
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_default" style=3D"font-family:comic sa=
ns ms,sans-serif">thanks a lot<br></div></div><br><div class=3D"gmail_quote=
"><div dir=3D"ltr">On Sun, Jan 6, 2019 at 5:58 PM Sviatoslav Sydorenko &lt;=
<a href=3D"mailto:[email protected]">[email protected]</a>&gt; wrote:<b=
r></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex=
;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr">=
<div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div di=
r=3D"ltr">You shouldn&#39;t be mixing several web frameworks (especially no=
t sync + async). I think you need to learn more about how the web works now=
 (HTTP, html, templating, etc.)<div><br></div><div>Regarding connecting SA =
to CherryPy, I&#39;ve already sent you a repo with such app example. Essent=
ial parts are db=C2=A0plugin (<a href=3D"https://github.com/Lawouach/Twisel=
ess/blob/master/lib/plugin/db.py" target=3D"_blank">https://github.com/Lawo=
uach/Twiseless/blob/master/lib/plugin/db.py</a>), db=C2=A0tool (<a href=3D"=
https://github.com/Lawouach/Twiseless/blob/master/lib/tool/db.py" target=3D=
"_blank">https://github.com/Lawouach/Twiseless/blob/master/lib/tool/db.py</=
a>) and models package (<a href=3D"https://github.com/Lawouach/Twiseless/tr=
ee/master/lib/model" target=3D"_blank">https://github.com/Lawouach/Twiseles=
s/tree/master/lib/model</a>).</div><div><br></div><div>Other parts are impo=
rtant too, like this user tool=C2=A0<a href=3D"https://github.com/Lawouach/=
Twiseless/blob/master/lib/tool/user.py#L30-L32" target=3D"_blank">https://g=
ithub.com/Lawouach/Twiseless/blob/master/lib/tool/user.py#L30-L32</a> which=
 retrieves a user from db=C2=A0shielding handlers from unauthorized access.=
</div><div><br></div><div>You have to learn the concepts of your chosen fra=
mework and then learn how to operate them.</div><div><br></div><div>For Che=
rryPy the process is roughly:</div><div>1. Have HTTP handlers which are bou=
nd to URLs. CherryPy will then call them whenever incoming HTTP request mat=
ches URLs.</div><div>2. HTTP handlers should return HTML (in common case). =
Since you&#39;ll probably want to render it from templates instead of hardc=
oded strings you&#39;ll probably need to learn Jinja2 or similar.</div><div=
>3. Since you want to access DB you&#39;ll need to use a DB driver or an OR=
M (SQLAlchemy in your case). You&#39;ll want to separate it&#39;s initializ=
ation code and put it into the plugin which will be your interface to the D=
B and will provide you a session object to work with it. Plugins are run in=
 separate threads and are accessible via a publish-subscribe bus.</div><div=
>4. To make accessing DB session easier you add a db tool which binds the s=
ession to current request object so that it&#39;s accessible through someth=
ing like `cherrypy.request.db`. Tools are callables executed at certain poi=
nts of request-response cycle, before and after request handler is called.<=
/div><div>5. With those things above in place it&#39;s possible to access a=
=C2=A0db=C2=A0from handlers (IRL you might want to separate the logic part =
into its own entity as well).</div></div></div></div></div><img src=3D"http=
s://t.sidekickopen76.com/s1t/o/5/f18dQhb0S7ks8dDMPbW2n0x6l2B9gXrN7sKj6v5dpz=
zVdDPRz2m64_PW3xgp7472TP1pf2mbxc201?si=3D5180645064310784&amp;pi=3D86d75c76=
-a919-42d8-f980-c8e766b07dcc&amp;ti=3Dnull" style=3D"display: none;" width=
=3D"1" height=3D"1"></div><br><div class=3D"gmail_quote"><div dir=3D"ltr">=
=D0=BD=D0=B4, 6 =D1=81=D1=96=D1=87. 2019 =D0=BE 14:51 vahid peivandy &lt;<a=
 href=3D"mailto:[email protected]" target=3D"_blank">tarfand.vahid@gm=
ail.com</a>&gt; =D0=BF=D0=B8=D1=88=D0=B5:<br></div><blockquote class=3D"gma=
il_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,2=
04,204);padding-left:1ex"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr=
"><div style=3D"font-family:&quot;comic sans ms&quot;,sans-serif">yes I wri=
te this tornado: <a href=3D"https://paste.ubuntu.com/p/3kcj6ZRgFQ/" target=
=3D"_blank">https://paste.ubuntu.com/p/3kcj6ZRgFQ/</a><br></div><div style=
=3D"font-family:&quot;comic sans ms&quot;,sans-serif">and now wanna connect=
 this code: <a href=3D"https://paste.ubuntu.com/p/BzmBTnrN54/" target=3D"_b=
lank">https://paste.ubuntu.com/p/BzmBTnrN54/</a>=C2=A0=C2=A0=C2=A0=C2=A0 to=
 tornado or cherrypy<br></div></div></div></div><br><div class=3D"gmail_quo=
te"><div dir=3D"ltr">On Sat, Jan 5, 2019 at 4:43 AM Tim Roberts &lt;<a href=
=3D"mailto:[email protected]" target=3D"_blank">[email protected]</a>&gt; wrote:<=
br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8e=
x;border-left:1px solid rgb(204,204,204);padding-left:1ex">
 =20
   =20
 =20
  <div bgcolor=3D"#FFFFFF">
    <div class=3D"gmail-m_5637883570198006251gmail-m_-8187802126341545521gm=
ail-m_-7333287049090533640moz-cite-prefix">vahid peivandy wrote:<br>
    </div>
    <blockquote type=3D"cite">
     =20
      <div dir=3D"ltr">
        <div dir=3D"ltr">
          <div style=3D"font-family:&quot;comic sans ms&quot;,sans-serif">I=
 cannot connect mu db on web server tornado
            or web server cherrypy this is my problem and see this page
            but not help me <br>
          </div>
          <div style=3D"font-family:&quot;comic sans ms&quot;,sans-serif"><=
a href=3D"https://tornado-sqlalchemy.readthedocs.io/en/latest/" target=3D"_=
blank">https://tornado-sqlalchemy.readthedocs.io/en/latest/</a><br>
          </div>
        </div>
      </div>
    </blockquote>
    <p>Have you ever done a web application of any kind before?=C2=A0 To me=
,
      it looks like you are trying to jump straight to the final steps
      of building a web app, when you haven&#39;t taken any of the early
      steps yet.=C2=A0 Don&#39;t take on too many new things at once.=C2=A0=
 Can you
      make a basic Tornado or CherryPy application work?=C2=A0 You start by
      displaying the basic &quot;hello world&quot; page.=C2=A0 Then you add=
 a couple of
      very basic pages with buttons or links to flip back and forth
      between them.=C2=A0 Then you substitute in some of your own text, to
      prove you understand the templating scheme.=C2=A0 At that point, you&=
#39;ll
      be more familiar with the framework, and the explanation on how to
      integrate SQLAlchemy will make more sense. <br>
    </p>
    <p>No one here is going to write your application for you.=C2=A0 We can
      offer guidelines, and we can help you work through the problems
      you encounter, but you have to do the work.<br>
    </p>
    <pre class=3D"gmail-m_5637883570198006251gmail-m_-8187802126341545521gm=
ail-m_-7333287049090533640moz-signature" cols=3D"72">--=20
Tim Roberts, <a class=3D"gmail-m_5637883570198006251gmail-m_-81878021263415=
45521gmail-m_-7333287049090533640moz-txt-link-abbreviated" href=3D"mailto:t=
[email protected]" target=3D"_blank">[email protected]</a>
Providenza &amp; Boekelheide, Inc.
</pre>
  </div>


<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;cherrypy-users&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:cherrypy-users+unsubscribe-/[email protected]" targ=
et=3D"_blank">cherrypy-users+unsubscribe-/[email protected]</a>.<br>
To post to this group, send email to <a href=3D"mailto:cherrypy-users@googl=
egroups.com" target=3D"_blank">cherrypy-users-/[email protected]</a>.<br>
Visit this group at <a href=3D"https://groups.google.com/group/cherrypy-use=
rs" target=3D"_blank">https://groups.google.com/group/cherrypy-users</a>.<b=
r>
For more options, visit <a href=3D"https://groups.google.com/d/optout" targ=
et=3D"_blank">https://groups.google.com/d/optout</a>.<br>
</blockquote></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;cherrypy-users&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:cherrypy-users+unsubscribe-/[email protected]" targ=
et=3D"_blank">cherrypy-users+unsubscribe-/[email protected]</a>.<br>
To post to this group, send email to <a href=3D"mailto:cherrypy-users@googl=
egroups.com" target=3D"_blank">cherrypy-users-/[email protected]</a>.<br>
Visit this group at <a href=3D"https://groups.google.com/group/cherrypy-use=
rs" target=3D"_blank">https://groups.google.com/group/cherrypy-users</a>.<b=
r>
For more options, visit <a href=3D"https://groups.google.com/d/optout" targ=
et=3D"_blank">https://groups.google.com/d/optout</a>.<br>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
 class=3D"gmail-m_5637883570198006251gmail_signature"><div dir=3D"ltr">Chee=
rs,<div>Sviatoslav.</div></div></div></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;cherrypy-users&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:cherrypy-users+unsubscribe-/[email protected]" targ=
et=3D"_blank">cherrypy-users+unsubscribe-/[email protected]</a>.<br>
To post to this group, send email to <a href=3D"mailto:cherrypy-users@googl=
egroups.com" target=3D"_blank">cherrypy-users-/[email protected]</a>.<br>
Visit this group at <a href=3D"https://groups.google.com/group/cherrypy-use=
rs" target=3D"_blank">https://groups.google.com/group/cherrypy-users</a>.<b=
r>
For more options, visit <a href=3D"https://groups.google.com/d/optout" targ=
et=3D"_blank">https://groups.google.com/d/optout</a>.<br>
</blockquote></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;cherrypy-users&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:cherrypy-users+unsubscribe-/[email protected]">cher=
rypy-users+unsubscribe-/[email protected]</a>.<br />
To post to this group, send email to <a href=3D"mailto:cherrypy-users@googl=
egroups.com">cherrypy-users-/[email protected]</a>.<br />
Visit this group at <a href=3D"https://groups.google.com/group/cherrypy-use=
rs">https://groups.google.com/group/cherrypy-users</a>.<br />
For more options, visit <a href=3D"https://groups.google.com/d/optout">http=
s://groups.google.com/d/optout</a>.<br />

--000000000000284a38057ed8056f--