librelist archives

« back to archive

Structure for small search app

Structure for small search app

From:
James Willson
Date:
2013-09-04 @ 16:08
Hi,

I am building my first (small) flask application which will simply do the
following:

 - Query a database and display the results
- Add items to the database
- Send emails to the admin via a contact page

My question is, does this make sense to have the following file structure?
I just want a clean logical way to divide up the code without going
overboard since it is a small application. I've also seen people dividing
their code up into models, views and forms.

    /app
        search.py ; Search function
        post.py ; Item posting function
        contact.py ; Contact page function
    /static ; Sites static files
    /templates ; Sites template files
config.py ; Sites configuration

Any input on this would be much appreciated. I understand it is subjective,
but I do feel like a certain structure might have advantages from the
perspective of readability.

James

Re: [flask] Structure for small search app

From:
Mauricio de Abreu Antunes
Date:
2013-09-04 @ 16:14
Well, if your structure is simple, you could want do to this:

/app
    __init__.py
    settings.py
    views/
    models/
/static
/templates

for a better (imho) structure I would use something like:
https://github.com/mattupstate/overholt


2013/9/4 James Willson <james_willson@hotmail.com>

> Hi,
>
> I am building my first (small) flask application which will simply do the
> following:
>
>  - Query a database and display the results
> - Add items to the database
> - Send emails to the admin via a contact page
>
> My question is, does this make sense to have the following file structure?
> I just want a clean logical way to divide up the code without going
> overboard since it is a small application. I've also seen people dividing
> their code up into models, views and forms.
>
>     /app
>         search.py ; Search function
>         post.py ; Item posting function
>         contact.py ; Contact page function
>     /static ; Sites static files
>     /templates ; Sites template files
> config.py ; Sites configuration
>
> Any input on this would be much appreciated. I understand it is
> subjective, but I do feel like a certain structure might have advantages
> from the perspective of readability.
>
> James
>
>


-- 
*Mauricio de Abreu Antunes*
*
*
Github: https://github.com/mauricioabreu
Twitter: https://twitter.com/maugzoide

Re: [flask] Structure for small search app

From:
Bruno Rocha
Date:
2013-09-04 @ 16:20
You can also use cookie cutter template
https://github.com/sloria/cookiecutter-flask


On Wed, Sep 4, 2013 at 1:14 PM, Mauricio de Abreu Antunes <
mauricio.abreua@gmail.com> wrote:

> Well, if your structure is simple, you could want do to this:
>
> /app
>     __init__.py
>     settings.py
>     views/
>     models/
> /static
> /templates
>
> for a better (imho) structure I would use something like:
> https://github.com/mattupstate/overholt
>
>
> 2013/9/4 James Willson <james_willson@hotmail.com>
>
>> Hi,
>>
>> I am building my first (small) flask application which will simply do the
>> following:
>>
>>  - Query a database and display the results
>> - Add items to the database
>> - Send emails to the admin via a contact page
>>
>> My question is, does this make sense to have the following file
>> structure? I just want a clean logical way to divide up the code without
>> going overboard since it is a small application. I've also seen people
>> dividing their code up into models, views and forms.
>>
>>     /app
>>         search.py ; Search function
>>         post.py ; Item posting function
>>         contact.py ; Contact page function
>>     /static ; Sites static files
>>     /templates ; Sites template files
>> config.py ; Sites configuration
>>
>> Any input on this would be much appreciated. I understand it is
>> subjective, but I do feel like a certain structure might have advantages
>> from the perspective of readability.
>>
>> James
>>
>>
>
>
> --
> *Mauricio de Abreu Antunes*
> *
> *
> Github: https://github.com/mauricioabreu
> Twitter: https://twitter.com/maugzoide
>

Re: [flask] Structure for small search app

From:
James Zildjian
Date:
2013-09-04 @ 16:28
Ok, I will look into those, thank you. It's worth noting that when I say
"database" what I am actually refering to is search a SOLR installation,
rather than a SQL database.


On Wed, Sep 4, 2013 at 5:20 PM, Bruno Rocha <rochacbruno@gmail.com> wrote:

> You can also use cookie cutter template
> https://github.com/sloria/cookiecutter-flask
>
>
> On Wed, Sep 4, 2013 at 1:14 PM, Mauricio de Abreu Antunes <
> mauricio.abreua@gmail.com> wrote:
>
>> Well, if your structure is simple, you could want do to this:
>>
>> /app
>>     __init__.py
>>     settings.py
>>     views/
>>     models/
>> /static
>> /templates
>>
>> for a better (imho) structure I would use something like:
>> https://github.com/mattupstate/overholt
>>
>>
>> 2013/9/4 James Willson <james_willson@hotmail.com>
>>
>>> Hi,
>>>
>>> I am building my first (small) flask application which will simply do
>>> the following:
>>>
>>>  - Query a database and display the results
>>> - Add items to the database
>>> - Send emails to the admin via a contact page
>>>
>>> My question is, does this make sense to have the following file
>>> structure? I just want a clean logical way to divide up the code without
>>> going overboard since it is a small application. I've also seen people
>>> dividing their code up into models, views and forms.
>>>
>>>     /app
>>>         search.py ; Search function
>>>         post.py ; Item posting function
>>>         contact.py ; Contact page function
>>>     /static ; Sites static files
>>>     /templates ; Sites template files
>>> config.py ; Sites configuration
>>>
>>> Any input on this would be much appreciated. I understand it is
>>> subjective, but I do feel like a certain structure might have advantages
>>> from the perspective of readability.
>>>
>>> James
>>>
>>>
>>
>>
>> --
>> *Mauricio de Abreu Antunes*
>> *
>> *
>> Github: https://github.com/mauricioabreu
>> Twitter: https://twitter.com/maugzoide
>>
>
>

Re: [flask] Structure for small search app

From:
James Willson
Date:
2013-09-04 @ 16:28
Ok, I will look into those, thank you. It's worth noting that when I say
"database" what I am actually refering to is search a SOLR installation,
rather than a SQL database.


On Wed, Sep 4, 2013 at 5:28 PM, James Zildjian <mail@employ.com> wrote:

> Ok, I will look into those, thank you. It's worth noting that when I say
> "database" what I am actually refering to is search a SOLR installation,
> rather than a SQL database.
>
>
> On Wed, Sep 4, 2013 at 5:20 PM, Bruno Rocha <rochacbruno@gmail.com> wrote:
>
>> You can also use cookie cutter template
>> https://github.com/sloria/cookiecutter-flask
>>
>>
>> On Wed, Sep 4, 2013 at 1:14 PM, Mauricio de Abreu Antunes <
>> mauricio.abreua@gmail.com> wrote:
>>
>>> Well, if your structure is simple, you could want do to this:
>>>
>>> /app
>>>     __init__.py
>>>     settings.py
>>>     views/
>>>     models/
>>> /static
>>> /templates
>>>
>>> for a better (imho) structure I would use something like:
>>> https://github.com/mattupstate/overholt
>>>
>>>
>>> 2013/9/4 James Willson <james_willson@hotmail.com>
>>>
>>>> Hi,
>>>>
>>>> I am building my first (small) flask application which will simply do
>>>> the following:
>>>>
>>>>  - Query a database and display the results
>>>> - Add items to the database
>>>> - Send emails to the admin via a contact page
>>>>
>>>> My question is, does this make sense to have the following file
>>>> structure? I just want a clean logical way to divide up the code without
>>>> going overboard since it is a small application. I've also seen people
>>>> dividing their code up into models, views and forms.
>>>>
>>>>     /app
>>>>         search.py ; Search function
>>>>         post.py ; Item posting function
>>>>         contact.py ; Contact page function
>>>>     /static ; Sites static files
>>>>     /templates ; Sites template files
>>>> config.py ; Sites configuration
>>>>
>>>> Any input on this would be much appreciated. I understand it is
>>>> subjective, but I do feel like a certain structure might have advantages
>>>> from the perspective of readability.
>>>>
>>>> James
>>>>
>>>>
>>>
>>>
>>> --
>>> *Mauricio de Abreu Antunes*
>>> *
>>> *
>>> Github: https://github.com/mauricioabreu
>>> Twitter: https://twitter.com/maugzoide
>>>
>>
>>
>

Re: [flask] Structure for small search app

From:
ureal frank
Date:
2013-09-04 @ 17:14
Can someone correct me on this:

if:
- I am a Flask newbie
- I am developing a tiny app
- Today I've only a public area but in the future, it will have a private
one too

I should think right now on a blueprint structure.

Cheers,
Frank


On Wed, Sep 4, 2013 at 5:28 PM, James Willson <james_willson@hotmail.com>wrote:

> Ok, I will look into those, thank you. It's worth noting that when I say
> "database" what I am actually refering to is search a SOLR installation,
> rather than a SQL database.
>
>
> On Wed, Sep 4, 2013 at 5:28 PM, James Zildjian <mail@employ.com> wrote:
>
>> Ok, I will look into those, thank you. It's worth noting that when I say
>> "database" what I am actually refering to is search a SOLR installation,
>> rather than a SQL database.
>>
>>
>> On Wed, Sep 4, 2013 at 5:20 PM, Bruno Rocha <rochacbruno@gmail.com>wrote:
>>
>>> You can also use cookie cutter template
>>> https://github.com/sloria/cookiecutter-flask
>>>
>>>
>>> On Wed, Sep 4, 2013 at 1:14 PM, Mauricio de Abreu Antunes <
>>> mauricio.abreua@gmail.com> wrote:
>>>
>>>> Well, if your structure is simple, you could want do to this:
>>>>
>>>> /app
>>>>     __init__.py
>>>>     settings.py
>>>>     views/
>>>>     models/
>>>> /static
>>>> /templates
>>>>
>>>> for a better (imho) structure I would use something like:
>>>> https://github.com/mattupstate/overholt
>>>>
>>>>
>>>> 2013/9/4 James Willson <james_willson@hotmail.com>
>>>>
>>>>> Hi,
>>>>>
>>>>> I am building my first (small) flask application which will simply do
>>>>> the following:
>>>>>
>>>>>  - Query a database and display the results
>>>>> - Add items to the database
>>>>> - Send emails to the admin via a contact page
>>>>>
>>>>> My question is, does this make sense to have the following file
>>>>> structure? I just want a clean logical way to divide up the code without
>>>>> going overboard since it is a small application. I've also seen people
>>>>> dividing their code up into models, views and forms.
>>>>>
>>>>>     /app
>>>>>         search.py ; Search function
>>>>>         post.py ; Item posting function
>>>>>         contact.py ; Contact page function
>>>>>     /static ; Sites static files
>>>>>     /templates ; Sites template files
>>>>> config.py ; Sites configuration
>>>>>
>>>>> Any input on this would be much appreciated. I understand it is
>>>>> subjective, but I do feel like a certain structure might have advantages
>>>>> from the perspective of readability.
>>>>>
>>>>> James
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> *Mauricio de Abreu Antunes*
>>>> *
>>>> *
>>>> Github: https://github.com/mauricioabreu
>>>> Twitter: https://twitter.com/maugzoide
>>>>
>>>
>>>
>>
>

Re: [flask] Structure for small search app

From:
Matthew Schmoyer
Date:
2013-09-04 @ 17:23
Blueprints can be helpful when building a larger app (You can break the
structure up into several view blueprints), but on smaller apps one main
app view should suffice.

- Matt


On Wed, Sep 4, 2013 at 1:14 PM, ureal frank <urealfrank@gmail.com> wrote:

> Can someone correct me on this:
>
> if:
> - I am a Flask newbie
> - I am developing a tiny app
> - Today I've only a public area but in the future, it will have a private
> one too
>
> I should think right now on a blueprint structure.
>
> Cheers,
> Frank
>
>
> On Wed, Sep 4, 2013 at 5:28 PM, James Willson <james_willson@hotmail.com>wrote:
>
>> Ok, I will look into those, thank you. It's worth noting that when I say
>> "database" what I am actually refering to is search a SOLR installation,
>> rather than a SQL database.
>>
>>
>> On Wed, Sep 4, 2013 at 5:28 PM, James Zildjian <mail@employ.com> wrote:
>>
>>> Ok, I will look into those, thank you. It's worth noting that when I say
>>> "database" what I am actually refering to is search a SOLR installation,
>>> rather than a SQL database.
>>>
>>>
>>> On Wed, Sep 4, 2013 at 5:20 PM, Bruno Rocha <rochacbruno@gmail.com>wrote:
>>>
>>>> You can also use cookie cutter template
>>>> https://github.com/sloria/cookiecutter-flask
>>>>
>>>>
>>>> On Wed, Sep 4, 2013 at 1:14 PM, Mauricio de Abreu Antunes <
>>>> mauricio.abreua@gmail.com> wrote:
>>>>
>>>>> Well, if your structure is simple, you could want do to this:
>>>>>
>>>>> /app
>>>>>     __init__.py
>>>>>     settings.py
>>>>>     views/
>>>>>     models/
>>>>> /static
>>>>> /templates
>>>>>
>>>>> for a better (imho) structure I would use something like:
>>>>> https://github.com/mattupstate/overholt
>>>>>
>>>>>
>>>>> 2013/9/4 James Willson <james_willson@hotmail.com>
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I am building my first (small) flask application which will simply do
>>>>>> the following:
>>>>>>
>>>>>>  - Query a database and display the results
>>>>>> - Add items to the database
>>>>>> - Send emails to the admin via a contact page
>>>>>>
>>>>>> My question is, does this make sense to have the following file
>>>>>> structure? I just want a clean logical way to divide up the code without
>>>>>> going overboard since it is a small application. I've also seen people
>>>>>> dividing their code up into models, views and forms.
>>>>>>
>>>>>>     /app
>>>>>>         search.py ; Search function
>>>>>>         post.py ; Item posting function
>>>>>>         contact.py ; Contact page function
>>>>>>     /static ; Sites static files
>>>>>>     /templates ; Sites template files
>>>>>> config.py ; Sites configuration
>>>>>>
>>>>>> Any input on this would be much appreciated. I understand it is
>>>>>> subjective, but I do feel like a certain structure might have advantages
>>>>>> from the perspective of readability.
>>>>>>
>>>>>> James
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> *Mauricio de Abreu Antunes*
>>>>> *
>>>>> *
>>>>> Github: https://github.com/mauricioabreu
>>>>> Twitter: https://twitter.com/maugzoide
>>>>>
>>>>
>>>>
>>>
>>
>

Re: [flask] Structure for small search app

From:
ureal frank
Date:
2013-09-04 @ 17:39
On Wed, Sep 4, 2013 at 6:23 PM, Matthew Schmoyer <mschmoyer@50onred.com>wrote:

> Blueprints can be helpful when building a larger app (You can break the
> structure up into several view blueprints), but on smaller apps one main
> app view should suffice.
>

10x :-)


>
> - Matt
>
>
> On Wed, Sep 4, 2013 at 1:14 PM, ureal frank <urealfrank@gmail.com> wrote:
>
>> Can someone correct me on this:
>>
>> if:
>> - I am a Flask newbie
>> - I am developing a tiny app
>> - Today I've only a public area but in the future, it will have a private
>> one too
>>
>> I should think right now on a blueprint structure.
>>
>> Cheers,
>> Frank
>>
>>
>> On Wed, Sep 4, 2013 at 5:28 PM, James Willson <james_willson@hotmail.com>wrote:
>>
>>> Ok, I will look into those, thank you. It's worth noting that when I say
>>> "database" what I am actually refering to is search a SOLR installation,
>>> rather than a SQL database.
>>>
>>>
>>> On Wed, Sep 4, 2013 at 5:28 PM, James Zildjian <mail@employ.com> wrote:
>>>
>>>> Ok, I will look into those, thank you. It's worth noting that when I
>>>> say "database" what I am actually refering to is search a SOLR
>>>> installation, rather than a SQL database.
>>>>
>>>>
>>>> On Wed, Sep 4, 2013 at 5:20 PM, Bruno Rocha <rochacbruno@gmail.com>wrote:
>>>>
>>>>> You can also use cookie cutter template
>>>>> https://github.com/sloria/cookiecutter-flask
>>>>>
>>>>>
>>>>> On Wed, Sep 4, 2013 at 1:14 PM, Mauricio de Abreu Antunes <
>>>>> mauricio.abreua@gmail.com> wrote:
>>>>>
>>>>>> Well, if your structure is simple, you could want do to this:
>>>>>>
>>>>>> /app
>>>>>>     __init__.py
>>>>>>     settings.py
>>>>>>     views/
>>>>>>     models/
>>>>>> /static
>>>>>> /templates
>>>>>>
>>>>>> for a better (imho) structure I would use something like:
>>>>>> https://github.com/mattupstate/overholt
>>>>>>
>>>>>>
>>>>>> 2013/9/4 James Willson <james_willson@hotmail.com>
>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> I am building my first (small) flask application which will simply
>>>>>>> do the following:
>>>>>>>
>>>>>>>  - Query a database and display the results
>>>>>>> - Add items to the database
>>>>>>> - Send emails to the admin via a contact page
>>>>>>>
>>>>>>> My question is, does this make sense to have the following file
>>>>>>> structure? I just want a clean logical way to divide up the code without
>>>>>>> going overboard since it is a small application. I've also seen people
>>>>>>> dividing their code up into models, views and forms.
>>>>>>>
>>>>>>>     /app
>>>>>>>         search.py ; Search function
>>>>>>>         post.py ; Item posting function
>>>>>>>         contact.py ; Contact page function
>>>>>>>     /static ; Sites static files
>>>>>>>     /templates ; Sites template files
>>>>>>> config.py ; Sites configuration
>>>>>>>
>>>>>>> Any input on this would be much appreciated. I understand it is
>>>>>>> subjective, but I do feel like a certain structure might have advantages
>>>>>>> from the perspective of readability.
>>>>>>>
>>>>>>> James
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> *Mauricio de Abreu Antunes*
>>>>>> *
>>>>>> *
>>>>>> Github: https://github.com/mauricioabreu
>>>>>> Twitter: https://twitter.com/maugzoide
>>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
>

Re: [flask] Structure for small search app

From:
Matthew Schmoyer
Date:
2013-09-04 @ 16:19
While this is somewhat opinionated, I would create a model with the search
and post function as class methods (See:
http://pythonhosted.org/Flask-SQLAlchemy/models.html).  Doing so you can
replace search.py, post.py, and contact.py with a models.py (to store your
db models) and a views.py (to store your controller functions).

On the subject, here are two good boilerplates for Flask:
1) https://github.com/imwilsonxu/fbone
2) https://github.com/mitsuhiko/flask/wiki/Large-app-how-to (This one is
kind of a recommended structure for large apps, but if you start your small
app this way and who knows, but say it begins to expand into a larger one
you can make it more scalable from the start)

- Matt


On Wed, Sep 4, 2013 at 12:08 PM, James Willson <james_willson@hotmail.com>wrote:

> Hi,
>
> I am building my first (small) flask application which will simply do the
> following:
>
>  - Query a database and display the results
> - Add items to the database
> - Send emails to the admin via a contact page
>
> My question is, does this make sense to have the following file structure?
> I just want a clean logical way to divide up the code without going
> overboard since it is a small application. I've also seen people dividing
> their code up into models, views and forms.
>
>     /app
>         search.py ; Search function
>         post.py ; Item posting function
>         contact.py ; Contact page function
>     /static ; Sites static files
>     /templates ; Sites template files
> config.py ; Sites configuration
>
> Any input on this would be much appreciated. I understand it is
> subjective, but I do feel like a certain structure might have advantages
> from the perspective of readability.
>
> James
>
>