librelist archives

« back to archive

How to create URLs from DB

How to create URLs from DB

From:
Carlos Vazquez
Date:
2014-11-17 @ 19:34
Hello.-

I need help to create a set of independent URLs from data retrieved from a
DB (MySQL) such as:

https//mysite.net/user/#123
https//mysite.net/user/#456
https//mysite.net/user/#789
...
and every user has to login with their own OpenId account.

The data retrieved from the DB will be static and will only change once a
year, twice at the most. I'll use a regular Jinja Template for the layout
and Bootstrap for the CSS part.

I come from a php background, I'm learning Python and Flask and although I
see Flask is way simpler, I still can't figure this one out, should I use a
Blueprint ? regarding the DB connection, is there a solution other than
SQLAlchemy ?

Any help will be appreciated.

Thanks in advance

Best regards

Carlos Vazquez

Re: [flask] How to create URLs from DB

From:
Cornelius Kölbel
Date:
2014-11-17 @ 20:03
Hi Carlos,

you can have one function with such a route:

@app.route("/user/<id>")
def user_function(id=None)
    # fetch ID from database
    # do something
    return something else.

Kind regards
Cornelius

Am 17.11.2014 um 20:34 schrieb Carlos Vazquez:
> Hello.-
>
> I need help to create a set of independent URLs from data retrieved
> from a DB (MySQL) such as:
>
> https//mysite.net/user/#123 <http://mysite.net/user/#123>
> https//mysite.net/user/#456 <http://mysite.net/user/#456>
> https//mysite.net/user/#789 <http://mysite.net/user/#789>
> ...
> and every user has to login with their own OpenId account.
>
> The data retrieved from the DB will be static and will only change
> once a year, twice at the most. I'll use a regular Jinja Template for
> the layout and Bootstrap for the CSS part.
>
> I come from a php background, I'm learning Python and Flask and
> although I see Flask is way simpler, I still can't figure this one
> out, should I use a Blueprint ? regarding the DB connection, is there
> a solution other than SQLAlchemy ?
>
> Any help will be appreciate d.
>
> Thanks in advance
>
> Best regards
>
> Carlos Vazquez

Re: [flask] How to create URLs from DB

From:
Åsmund Tokheim
Date:
2014-11-17 @ 20:47
Hi
Note that it is not recommended to use URLs like 
https://mysite.net/user/#123. Anything after the #-sign should normally 
only be processed by the client 
(http://en.wikipedia.org/wiki/Fragment_identifier). You can instead use 
the route @app.route("/user/<int:id>"). Flask will then automatically 
check and convert the id to an int, or give a useful error message if the 
input is invalid.
RegardsÅsmund

Date: Mon, 17 Nov 2014 21:03:17 +0100
From: cornelius@privacyidea.org
Subject: Re: [flask] How to create URLs from DB
To: flask@librelist.com


  
    
  
  
    Hi Carlos,

    

    you can have one function with such a route:

    

    @app.route("/user/<id>")

    def user_function(id=None)

        # fetch ID from database

        # do something

        return something else.

    

    Kind regards

    Cornelius

    

    Am 17.11.2014 um 20:34 schrieb Carlos
      Vazquez:

    
    Hello.-
      

      
      I need help to create a set of independent URLs from data
        retrieved from a DB (MySQL) such as:
      

      
      https//mysite.net/user/#123
      https//mysite.net/user/#456

      
      https//mysite.net/user/#789

      
      ...
      and every user has to login with their own OpenId account.
      

      
      The data retrieved from the DB will be static and will only
        change once a year, twice at the most. I'll use a regular Jinja
        Template for the layout and Bootstrap for the CSS part.
      

      
      I come from a php background, I'm learning Python and Flask
        and although I see Flask is way simpler, I still can't figure
        this one out, should I use a Blueprint ? regarding the DB
        connection, is there a solution other than SQLAlchemy ?
      

      
      Any help will be appreciate d.
      

      
      Thanks in advance
      

      
      Best regards
      

      
      Carlos Vazquez
     		 	   		  

Re: [flask] How to create URLs from DB

From:
Carlos Vazquez
Date:
2014-11-17 @ 21:20
O.K. Thanks to both of you, I'll follow your advice.

Best regards.

On Mon Nov 17 2014 at 2:51:57 PM Åsmund Tokheim <tokheim@outlook.com> wrote:

> Hi
>
> Note that it is not recommended to use URLs like
> https://mysite.net/user/#123. Anything after the #-sign should normally
> only be processed by the client (
> http://en.wikipedia.org/wiki/Fragment_identifier). You can instead use
> the route @app.route("/user/<int:id>"). Flask will then automatically check
> and convert the id to an int, or give a useful error message if the input
> is invalid.
>
> Regards
> Åsmund
>
> ------------------------------
> Date: Mon, 17 Nov 2014 21:03:17 +0100
> From: cornelius@privacyidea.org
> Subject: Re: [flask] How to create URLs from DB
> To: flask@librelist.com
>
>
> Hi Carlos,
>
> you can have one function with such a route:
>
> @app.route("/user/<id>")
> def user_function(id=None)
>     # fetch ID from database
>     # do something
>     return something else.
>
> Kind regards
> Cornelius
>
> Am 17.11.2014 um 20:34 schrieb Carlos Vazquez:
>
> Hello.-
>
>  I need help to create a set of independent URLs from data retrieved from
> a DB (MySQL) such as:
>
>  https//mysite.net/user/#123
> https//mysite.net/user/#456
>  https//mysite.net/user/#789
>  ...
> and every user has to login with their own OpenId account.
>
>  The data retrieved from the DB will be static and will only change once
> a year, twice at the most. I'll use a regular Jinja Template for the layout
> and Bootstrap for the CSS part.
>
>  I come from a php background, I'm learning Python and Flask and although
> I see Flask is way simpler, I still can't figure this one out, should I use
> a Blueprint ? regarding the DB connection, is there a solution other than
> SQLAlchemy ?
>
>  Any help will be appreciate d.
>
>  Thanks in advance
>
>  Best regards
>
>  Carlos Vazquez
>
>