#web-development

2 messages ยท Page 29 of 1

vagrant adder
#

Tried resetting your server completely?

vagrant adder
#

sure

#

not that big of an apache user but let's see

wide shoal
split mirage
#

Anyone know how to download or screenshot all liked Instagram posts?

#

Automatically of course.

#

Preferably both, download the image and screenshot.

rigid laurel
#

I'm not sure if Instagram allows that, but if it does then web scraping with beautiful soup should work.

stoic sorrel
#

I am working on technical test in python, and seems like its a base for simple queue-processing app. I was mostly working with other languages before.
What are usual ways of putting things to work together in python? is dependency injection common? any particular lib? is repository pattern for db common here?
are interfaces and abstract classes common?

fallow herald
#

@split mirage pyppeteer library will do that for you, dowload and screenshot. fast and clear.

split mirage
#

@fallow herald Awesome! You think Instagram might get mad or shut down my account?

#

Maybe even shadowban me for acting automatically?

vagrant adder
#

@split mirage instagram doesnt allow crawling

tacit grove
#

Web scraping instagram is against instagram's TOS, and so it also breaks rule 5 of our server, thus we will not help you with that or facilitate any such discussion here. thank you for understanding @fallow herald

#

!rule 5

lavish prismBOT
#

5. We will not help you with anything that might break a law or the terms of service of any other community, site, service, or otherwise - No piracy, brute-forcing, captcha circumvention, sneaker bots, or anything else of that nature.

tacit grove
#

whoops, wrong ping

#

@split mirage

rich walrus
#

Hey, so I have a wordpress install on apache localhost:8000 at root, and wiki on root/wiki. When I try to access the wiki via site.com/wiki it works, but when I click a link from wordpress, like site.com/wiki it reformats it to be site.com:8000/wiki and breaks the link. I'm using an nginx reverse proxy infront of apache, redirecting all port 80 traffic to the localhost:8000 where apache is. How to fix?

warm narwhal
#

do you guys have a preference between uwsgi vs gunicorn and why ?

stiff totem
#

hey guys, how can i make a query that filter selected tracks for this django model:

class Chart(models.Model):
   title = models.CharField()
   ....
class Edition(models.Model):
    chart = models.ForeignKey("Chart", ....)
    ....
class Item(models.Model):
    edition = models.ForeignKey("Edition", )
    object_id = models.UUID(db_index=True)  #Track Object
#

i tried to get this by doing this:

c = Chart.objects.get(id=1)
list_ids = [i.object_id for i in c.editions.last().items.all()]

but it seems very dull idea to get. Like is there some sort of way to get it as a TrackObject?

vagrant adder
#

@warm narwhal
Gunicorn just because its so frickin easy to start a server

limber orchid
#

I recently had to do a soft computer reset and had to reinstall python and flask, now when I try to run flask locally I get the following error.

#

Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.

#

I don't remember having to set up environment variables or paths the last time I had a local dev server running

#

I'm using command prompt in windows 10, navigate to the directory, do set FLASK_APP = flask_app enter then flask run

olive wharf
#

^building on that, what does FLASK_APP look for, and how

proper hinge
#

a variable named app in an app.py file

olive wharf
#

does it call app.run?

proper hinge
#

but you can just specify your own location so you don't need to understand in depth how it works

olive wharf
#

Cause my issue is I don't have the Flask variable in the applications entry point

#

I start it through a manager

proper hinge
#

wdym a manager

olive wharf
#
app
|_    site
|    |_    manager
|_    main.py``` ```py
manager = Manager()

if __name__ == "__main__":
    endpoints = (dropdown, fill_in, multi_choice, data_endpoint)
    manager.load_api_resources(endpoints)

    args = parser.parse_args()
    manager.run(debug=args.production)
#
class Manager:
    def __init__(self):
        self.app = Flask(__name__)
        self.api = Api(self.app)
        self.db = MongoDb()
        self.log = logging.getLogger(__name__)

        self.log.debug("Manager initialized")

    def add_from_dict(self, dic):
        for endpoint, class_ in dic.items():
            class_.add(self, endpoint)

    def load_api_resources(self, endpoints):
        for endpoint in endpoints:
            self.add_from_dict(endpoint)

    def run(self, debug):
        self.app.run(debug=debug)
#

Is basically what I do

#

It might be silly, but worked locally running it with python directly

proper hinge
#

run() is fine for local testing but you need a proper wsgi for production

#

.e.g gunicorn

#

I'm not sure if you can specify the flask app as an instance variable of another variable, like manager.app

olive wharf
#

Yeah, that part is completely out of scope for my current brain.

proper hinge
#

but you could trry

#

the other choice is to subclass the flask app class instead

olive wharf
#

So something like this? ENV FLASK_APP app.main:manager.app

proper hinge
#

yeah

olive wharf
#

Else i guess I can just inject the flask app in main to the manager

#

ยฏ_(ใƒ„)_/ยฏ

proper hinge
#

I think subclassing makes more sense

#

(though I wouldn't put the routes in there)

olive wharf
#

I have my routes be added in the manager

#

So that parts fine

proper hinge
#

It looks like you could simplify that by using blueprints

#

But what I meant was, for the example they give, I wouldn't have defined my routes inside the factory

#

It's meant to be a simple example so fair enough

olive wharf
#

How far out swimming am i for a proper flask (rest) server

proper hinge
#

The code itself looks close to done but I didn't spend a lot of time analysing it all

#

But you seem to have nothing in terms of deployment

olive wharf
#

Correct

#

I am lost in that regards

#

I just can't seem to wrap my head around it

proper hinge
#

you said you got a mongodb container running right

olive wharf
#

Yup

#

At least, it didnt crash

#

No idea if it actually works since i never got a flask container going

proper hinge
#

What you could do next is create the docker compose file

olive wharf
#
version: '3'
services:
  web:
    build: .
    ports:
      - "5000:5000"
  mongo:
    image: "mongo:3.4.22"```
#

?

proper hinge
#

ok cool

olive wharf
#

Lemme push what i have atm to a new branch

#

If only my internet would be stable, i could actually push it as well :|

#

I have this at least ```
FROM python:3.7-alpine

WORKDIR /code
COPY . .

RUN apk add --no-cache gcc musl-dev linux-headers
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

ENV FLASK_APP app.main:flask_app
ENV FLASK_RUN_HOST 0.0.0.0

CMD ["flask", "run"]```

#

Which seems to run a flask app, but no routes work

proper hinge
#

You're using pipenv so you should switch out the requirements.txt stuff

olive wharf
#

pipenv added a whole new level of i dont even know ๐Ÿ˜ฌ

proper hinge
#

alright you can deal with it later then

#

did you switch out FLASK_APP for what you said earlier?

limber orchid
#

@olive wharf so I should just include that init and etc in my flask_app.py? that simple?

olive wharf
#

yeah app.main:manager.app

#

You're asking the wrong guy @limber orchid ๐Ÿ˜…

limber orchid
#

oh sorry

olive wharf
#

Yeah I'm pretty lost atm

limber orchid
#

wait, you posted the class Manager..

#

hehe ok

proper hinge
#

@limber orchid all you should need to do is set the env variable to the correct value for your project structure

limber orchid
#

yeah this was the tut I was trying to follow

#

and it had worked for me before

#

maybe I need to go through the flask installation again, like start a new site and just transfer my code?

proper hinge
#

That seems somewhat drastic but if you want you can try

#

I'm not sure what the issue is

#

maybe try a different terminal

#

like git bash

#

or powershell

limber orchid
#

I did try powershell, it produced a different error about my app not being a recognized thing

olive wharf
#

Do you recon i should just subclass Flask with my manager?

proper hinge
#

@olive wharf No routes though? I don't follow how you are adding routes really. I'm just used to using a blueprint but to be honest not experience there cause someone else set up a blueprint for me. My suggestion is either try subclassing instead of having the app as an instance variable or add the routes differently

olive wharf
#

My routes are based on this py class ApiBase(Resource): @classmethod def add(cls, manager, path): cls.manager = manager cls.database = manager.db manager.api.add_resource(cls, path) So all endpoints inherit that

#

And i just call add with the app and a route in manager

proper hinge
#

I see

#

That looks alright actually

olive wharf
#

It was a way to help the others on the team be able to add routes

#

ยฏ_(ใƒ„)_/ยฏ

#

Lemme try the subclassing way and see if that changes anything

proper hinge
#

Another idea is to create a basic route and see if it works

#

@limber orchid The error says that the environment variable wasn't even set, I don't know why. If you rename your file to app.py then flask should be able to automatically figure things out

olive wharf
#

So it runs, but i still get 404 for all my endpoints :/

proper hinge
#

What about if you create a basic endpoint

#

without all the complication of your system to add it

limber orchid
#

ok I'll try that, thanks!

proper hinge
#

To be clear the server is live right?

#

Well I guess you would get something other than a 404 if it wasn't

olive wharf
#

It does say so, in the terminal as well

#

It shows the 404 in the debug prints

#

and GET requests to the correct routes

#

:| Run the whole build ... Whops typo, here we go again building

#
manager = Manager()

class Test(Resource):
    def get(self):
        return {"hello": "world"}
   
manager.api.add_resource(Test, "/")``` works
proper hinge
#

Have you tested the app locally before? Were your endpoints working then?

olive wharf
#

Yup

#

Its 100% working locally

#

when i run it through python directly

#

But i have an idea, lemme rebuild really quick..

proper hinge
#

and that's calling py endpoints = (dropdown, fill_in, multi_choice, data_endpoint) manager.load_api_resources(endpoints)

#

Seems you rely on that to make your app work locally

#

presumably your testing locally via main.py

olive wharf
#

yup

proper hinge
#

right so does flask run work locally?

#

my guess would be no

olive wharf
#

I don't think I've set it up either

proper hinge
#

You can make the dockerfile invoke main.py instead

#

But this wouldn't be a long term solution if you plan to switch to a proper WSGI

#

cause those want a thing similar to FLASK_APP

olive wharf
#

I mean, I do want to deploy

#

That's my end goal here

proper hinge
#

so in such case the solution would be to move the code in main.py inside like Manager.__init__()

olive wharf
#

aha

#

I think i get why the routes don't work

#

__name__ is app.main not __main__

proper hinge
#

You're calling run() inside that

#

which you wouldn't want to do if you're using flask run

olive wharf
#

Yeah, but I'm also adding my routes there

#

So if i move those outside..?

#

~Waiting for build

proper hinge
#

I suggested putting them inside Manager.__init__

olive wharf
#

Not a bad idea tbh

#

:^)

proper hinge
#

I am not sure you could put them after manager = Manager()

#

they may not get executed correctly ๐Ÿคท I don't know how flask loads the app

#

I thought for that reason they suggest using a factory

olive wharf
#

I believe the routes are working now, but I believe I'm missing a connection to the mongodb ๐Ÿค”

#

Yup

#

pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused

proper hinge
#

Containers on the same network should be able to talk to each other

#

And they would be on the same network by default I believe

#

but pretty sure not on localhost

olive wharf
#

Believe it needs to be the container_name:27017 ?

proper hinge
#

Docker networking is outside my knowledge tbh but I can try to dig something up

surreal thicket
#

id have to read through this when i have more time, but it seems like a good place to start

proper hinge
#

yeah that link looks good

#

by the way you can also specify environment variables in docker compose, that will come in handy for you I think

olive wharf
#

it's envirinment: KEY: value in the compose for env variables right?

#

That's what I was looking at, as all connect variables for my mongo setup have env overwrites

proper hinge
#

Yes but you misspelled it ๐Ÿ˜„

olive wharf
#

yes :)

#

.... And i put the variable on the mongo image, not web

#

๐Ÿคฆ๐Ÿฝ

dense salmon
#

Hi, I have apache and flask running, but when I try to import my py files into my main py it causes apache to just load forever and not display anything

olive wharf
#

Do i have to rebuild if i only change docker-compose.yml ?

proper hinge
#

no

olive wharf
#

good \o/

proper hinge
#

What about gunicorn and nginx ๐Ÿค”

olive wharf
#

That would be included in that step.

#

So would a lot of face against keyboarding

proper hinge
#

gunicorn has a guide for configuring nginx

#

and gunicorn itself is simple to set up

olive wharf
#

I frankly don't even know what they are.

proper hinge
#

nginx is a web server, gunicorn is a WSGI which is basically an interface the server uses to communicate with your app

olive wharf
#

Aha

stoic sorrel
#

Hi guys. Could you please point me to some example of production-ready, good quality cli/web app project structure? That would have all the fluff with all details like configs, dependency injection, containers and stuff? There seem to be tons of tutorials out there but all focused on one or two very specific things...

#

something that you consider an example of good quality and best practices

olive wharf
#

(but for django)

stoic sorrel
#

Was hoping for flask but django will certainly do. Thank you, kind stranger:)

olive wharf
#

@proper hinge got docker-compose to fire up a nginx and it seems to work

#

what's the next step? ๐Ÿค”

proper hinge
#

You didn't need to create a network

#

Also the web service doesn't need to have a volume for the code cause the code was copied inside the dockerfile

olive wharf
#

hm

#

I may need the network, when i plonk the frontend code into this somehow

#

unless I can run 2 docker containers on linode?

#

No idea, I've never done this before

#

Cause I have a node server that needs to be deployed as well

proper hinge
#

Yes you should be able to run them all on the same server if you want

olive wharf
#

kk

#

But is this where I try to get gunicorn to work with this?

proper hinge
#

Yeah

olive wharf
#

Do i just need to call the flask callabel with gunicorn? ๐Ÿค”

proper hinge
#

well no you also need to configure nginx

olive wharf
#

Oh, well then im lost :D

#

I was just going to change this in the web service command: gunicorn -b 0.0.0.0:8000 app.main:manager

#

and add RUN pip install gunicorn in the dockerfile

proper hinge
#

At this point I don't think I'm of much help anymore

#

I've not configured nginx

olive wharf
#

:(

proper hinge
#

I tried to once and was scared off

olive wharf
#

ouch

proper hinge
olive wharf
#

Big boost in my confidence :D

proper hinge
olive wharf
restive goblet
#

I never really did web development in the past, some html,css,and javascript but been a while
I would look to make a project similar to this : https://david-peter.de/quizzity/

Where should I start? I have no idea where to start/learn etc... Totally lost
Any advices, tips?

proper hinge
#

That site is open source so you can take a look to see what technologies they used

#

Normally people say start with HTML, then CSS, then JS for the front end

#

In terms of learning I mean

restive goblet
#

I learned html and css but don't remember much, do you know any sources to help me learn and have a good base to start working on the project I wanna do?

#

@proper hinge

proper hinge
#

I don't know if it's particularly good but I recall seeing a tutorial on MDN

rich walrus
#

I'd recommend learning Flask

#

start with just serving simple web pages, then add some css to make em pretty, then add JS to add fancy buttons & stuff

#

then learn about DBs, session management

restive goblet
#

how can Flask help for that project?

rich walrus
#

AH nvm, that looks very JS heavy

restive goblet
#

I mean it just want something with like a city and you can click parks, or the main streets of the city, things like that.
Something similar to the link I sent, or like this also : https://online.seterra.com/en/vgp/3209

#

is that also JS heavy?

rich walrus
#

Yes

#

Anything instantly reactive like that will have to be.

restive goblet
#

oh kk

#

so I could make a project like that with only html,css,js ?

rich walrus
#

Theoretically yes

#

like that last example you gave is essentialy an SVG image with lots of JS watching what you click on it.

restive goblet
#

and is that too hard for a beginner? I don't mind taking a lot of time to do that, just wanna learn in the process

#

oh I see

#

the david-peter thing is a lot more complicated then?

rich walrus
#

Yes, I'd say so.

#

You will need some backend setup too. HTML/css/JS is all front-end stuff.

#

The 2nd link's svg looks programatically generated somehow, and thats done on thebackend.

#

It might just be a library or something

#

If you're a beginner though, this stuff is really complicated. I've been learning for a few months and can't do stuff like that ๐Ÿ˜›

restive goblet
#

oh okay haha, it's too complicated (the first link? or for both links?)

#

yeah the first one is using a lot of libraries too , in his readme it says : leadflet, lodash, jquery, font-awesome, animate.css, GeoNames, Natural earth, Tilemill, python-mbtiles

#

''You will need some backend setup too. HTML/css/JS is all front-end stuff.'':
backend stuff would be the database for all the information about the cities and stuff?

rich walrus
#

yes, and also serving your html/css/js

#

websites need a server after all

#

(of which I would recommend you start with flask, because its super easy and you can mostly ignore backend stuff if you prefer by keeping it super simple, like 10 lines of python code)

restive goblet
#

what can I build with flask basically?

#

not really sure I get what flask does

proper hinge
#

It can process requests the server receives and render an HTML page from a template for example

#

Or you can write an API with it

#

Sometimes you need processing to be done on the server rather than on the client side

restive goblet
#

oh I see, but not sure how Flask can help me make the geography thing?

rich walrus
#

you need a server to send that web-page to people

#

flask is a simple server

#

you can write all the html you want, but its gonna be useless if its never served

restive goblet
#

so basically I need Flask + html + css + JS to make all that possible?

rich walrus
#

If someone goes to your website, flask is gonna be like "here, take all this html/css/JS"

#

Yes

#

you don't need flask, but its probably the easiest

restive goblet
#

yeah sounds complicated for beginner, idk if I can do that, might try though

rich walrus
#

could use django, or if you want to go non python, PHP

restive goblet
#

nah would prefer python

#

django is like flask right?

#

but more complicated?

native root
#

They serve similar purposes. In my opinion, django is more heavyweight and more opinionated, and more complex. However, it does not suffer from some of the limitations and provides a thorough framework that guides the building of an application.

#

For your first project I would highly recommend flask over django, as the limitations of flask are unlikely to bite you, and understanding view/model/admin, migrations, and database is often overkill

cursive cairn
#

What are the limitations of Flask vs. Django though?

native root
#

Flask does not come with built in orm, an extensible and complex admin interface, built in module handling, settings interfaces, etc

misty fossil
#

I need help with Web development.

native root
#

!ask

lavish prismBOT
#
ask

Asking good questions will yield a much higher chance of a quick response:

โ€ข Don't ask to ask your question, just go ahead and tell us your problem.
โ€ข Try to solve the problem on your own first, we're not going to write code for you.
โ€ข Show us the code you've tried and any errors or unexpected results it's giving
โ€ข Keep your patience while we're helping you.

You can find a much more detailed explanation on our website.

misty fossil
#

I am thinking of starting my project and I doubt that Django supports Bootstrap!!!

native root
#

They are compatible

misty fossil
#

K

vagrant adder
#

What does django have to do with bootstrap

scarlet heart
#

django does support bootstrap right?

vagrant adder
#

yes

native tide
#
        bootstrap(tmpdir=tmpdir)```
#

It's just a short piece of code for setting up bootstrap

clever ibex
#

anyone here familiar with django and/or mezzanine that could give me some help with something? I am trying to make a new page model in mezzanine inherited from the default page model, but I can't get my new fields to show up on the webpage, only the fields that are inherited by page ๐Ÿ˜ฆ

#

This does work and actually gets those fields to show up in a new page type selectable from my admin control panel, but I can't get any of those custom fields to show up on the published page, no matter what i have tried so far.

native tide
#

You can ask a link for pastebin. They provide you help with everything. I would recommend to ask in #help-coconut for pastebin link.

#

And yes I saw you used pastebin.

clever ibex
#

I'm sorry, what?

native tide
flint breach
#

or just wait 3 min

#

and someone will answer

clever ibex
#

yeah i dont feel the need to paste this across several channels

native tide
#

I don't use Django

#

or even create sites

clever ibex
#

and people in the django discord be like 'i dont use mezzanine'

#

and the mezzanine irc be like (wind sounds)

flint breach
#

what is mezzanine

clever ibex
#

mezzanine is a kind of ready to go framework for blogging over django

#

its django with moar templates

native tide
#

I would use zeta

clever ibex
#

some small diffs but not much

#

but I am new to all of it and am using this as a sort of educational process for myself

flint breach
#

oh django cms

native tide
#

I do websites with C# even though I suck

clever ibex
#

yuss

flint breach
#

you're more likely to get help with mezzanine people then django peeps tho

#

since it's build for django

clever ibex
#

mezzanine has only an irc channel with about 0 active members

flint breach
#

:/

clever ibex
#

been like that for years

flint breach
#

yea that's why community matters

native tide
#

That is obvious

flint breach
#

goodluck tho

clever ibex
#

yep. django is already kinda poorly documented, assumes you know a lot more than most do

flint breach
#

It's got a bit of a learning curve alright

clever ibex
#

mezzanine is even worse because its just like "oh, go look at the django docs for more info"

native tide
#

TaskScheduler.FromCurrentSynchronizationContext());

flint breach
#

why are you posting these things that add nothing to the discussion

native tide
#

Idk

clever ibex
#

I know my issue lies in one of two problems. Either I need to explicitly register those extra fields somewhere as existing

OR

I don't know their path.to.the.fieldname

flint breach
#

what error do you get

clever ibex
#

none!

#

aint that a bitch

native tide
#

Wait, can you send the pastebin link again?

flint breach
#

did u migrate?

clever ibex
#

yes i migrated

#

all those extra fields like ATP ATA etc, are present and accounted for in the admin page when creating a "weapon page"

#

but i cannot get them to show up in my template

native tide
#

I am stupid or is it true that you could "" on strings?

clever ibex
#

it works

#

the only issue is not being able to call up these things in my weaponpage template

#

btw, if you are curious of the terminology, i am trying to put together a database of weapons and armor from an old RPG game

flint breach
#

why are you inheriting from both page and rich text

vagrant adder
#

its django with moar templates
moar powwwa

flint breach
#

or is that the workflow

clever ibex
#

I just copied what they did for adding richtext page types

#

to be safe i inherited the same stuff.

#

within pages, mezzanine has default:

#

link pages

#

rich text pages

#

and some other

#

I am basing my custom page off of the mezzanine rich text page template

flint breach
#

yea browsed through the docs but im unsure what's the problem

#

goodluck tho

clever ibex
#

thank you very much. I feel i am very close.

#

See in my weapon page template I have {{ page.weaponpage.content|richtext_filters }} and this causes the page's main text body to appear.

#

but {{ page.weaponpage.atp }} comes up with nothing, and no error either which i found weird

clever ibex
#

figured it out with help from another server, not sure what i did wrong but trying page.weaponpage.ATP worked. Its case sensitive (i dropped the capital letters now). Weird because yesterday i tried with ATP and it still didnt work. Guess i just needed to sleep haha

winter flint
#

Does anyone know of a good way to check if Redis is running, but no workers?
The final line succeeds if there is a worker, but fails if there is not, but obviously it's not a good solution since it depends on the sleep

    task = self.task_func.apply_async()
    time.sleep(3)
    print(task.info.get('current', 0))
native tide
#

is there a way to have a folder with a bunch of markdown files.
And that folder is named like blog or smth
and so when you go to mywebsite.com/blog/subpage it displays the markdown file with the name subpage.md inside of the blog folder.
I think you could have some kind of python parser file using flask but I am not sure.

Essentially I want to be able to create markdown files, directly into the folder, upload it, and boom, html page created.

Another functionality I would like to have is someway to extract variables stored inside of the markdown files, such as:
subpage.md:

[blogpage-name]: My Blogpage Name

I don't remember if that's how you create vars but point remains.

#

This way I could get stuff like the title of the blog, date that it was published etc

vagrant adder
#

yes, there is a way

#

you just need to fix routing

vagrant adder
native tide
#
from tkinter import *
#Python default bank sample


from random import *
Bank = Tk()
Bank.config(bg = "grey")
Bank.geometry("1350x800")
Bank.title("")
#

That's a basic tkinter sample

#

Currently it's a bank program sample

frigid egret
#

Hi all.
I have a peculiar question about Django admin
Trying to validate an object before it's being saved with custom "save_model" function.

#

There is a list of inline objects and each of these inline objects has a boolean attribute

#

I'm trying to raise an error if more than one of these objects values is set to true

#

Can someone help me sort it out please?

native tide
#

Can you give me Pastebin link please?

lilac dagger
#

A flask question:
is is safe to edit request.data ?

eg, for example, a decorator that gets request.data and then sets it to decompressed data

surreal thicket
#

scanning the docs, it seems like it should be, because flask.request is thread-local, and it can't be passed to other threads anyway

#

hmm. maybe not. i think request is a werkzeug proxied local

#

Acts as a proxy for a werkzeug local. Forwards all operations to a proxied object. The only operations not supported for forwarding are right handed operands and any kind of assignment.

lilac dagger
#

hmm, how should I design this kind of decorator then
and yeah I'm asking cause PyCharm is telling me it's not assignable (but it works)

surreal thicket
#

whats your current code?

lilac dagger
#
def accepts_compressed(f):
    @functools.wraps(f)
    def view(*args, **kwargs):
        if request.headers.get("Content-Encoding", "") in ["gzip", "deflate"]:
            request.data = zlib.decompress(request.data)

        return f(*args, **kwargs)

    return view

basically I wanna do smth like this
(maybe not exactly decompress, but some data transformation)

#

I guess I could just do a get_data() function
and call it at beginning of each view

#

and call all processing needed from that func

surreal thicket
#

hmmmmmm. yeah thats a good question. herein lies the danger of using mysterious magical global objects

#

i think your get_data() idea makes the most sense

tranquil steeple
#

Can someone help

#

I'm creating a form with Python, Bootstrap 4, Flask & Jinja2

#

I want to change the input to have placeholder text and for input background to be black instead of white.

#
    <h1>CONTACT</h1>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Impedit voluptates minima cum odit eligendi, ut fuga suscipit dicta harum repellat assumenda dignissimos! Ad consequuntur ipsam deleniti quidem, quos obcaecati alias.</p>
  </div>

<div class="container col-lg-6">
    <div class="content-section">
        <form method="POST" action="">
          {{ form.hidden_tag() }}
          <fieldset class="form-group">
            <div class="form-group">
              {{ form.name.label(class="form-control-label") }}

                {% if form.name.error %}
                   {{ form.name(class="form-control form-control-sm is-invalid") }}
                   <div class="invalid-feedback">
                     {% for error in form.name.errors %}
                        <span>{{ error }}</span>  
                     {% endfor %}   
                   </div>
                   {% else %}
                     {{ form.name(class="form-control form-control-sm")}}    
                   {% endif %} 
            </div>
            <div class="form-group">
                {{ form.email.label(class="form-control-label") }}

                {% if form.email.error %}
                   {{ form.email(class="form-control form-control-sm is-invalid") }}
                   <div class="invalid-feedback">
                     {% for error in form.email.errors %}
                        <span>{{ error }}</span>  
                     {% endfor %}   
                   </div>
                   {% else %}
                     {{ form.email(class="form-control form-control-sm")}}    
                   {% endif %}  
            </div>
            
edgy smelt
#

Anyone have experience with using django to send push notifications to ios devices? I'm trying to attach an image to the notification and need a nudge in the right direction, because it seems like my payload json is structured properly.

native tide
#

Doing that is a very long process.

edgy smelt
#

Just adding images to the notifications? I can push simple alerts to iOS and 'rich' notifications work on Android

#

There isn't much documentation on this online so you're probably right

vestal trellis
native tide
#

is there a way to have a folder with a bunch of markdown files.
And that folder is named like blog or smth
and so when you go to mywebsite.com/blog/subpage it displays the markdown file with the name subpage.md inside of the blog folder.
I think you could have some kind of python parser file using flask but I am not sure.
Another functionality I would like to have is someway to extract variables stored inside of the markdown files, such as:
[blogpage-name]: My Blogpage Name

So lets say I have a folder called "blog/posts". Ok so htmlcssjs files are totally static, I don't change them ever. What I do is simply create a blogpost in markdown, upload it to the blog/posts folder. Then, the blog homepage search functionality is able to let you search for it, the "sort by date released" also is able to put it at the top, including its name title (extracted from variables) etc. Then when I go to the correct page, it will look for the markdown page, render it, and show the blog post that I made, all automated. The ONLY thing I do is create a markdown file with variables such as the name, author etc. and upload it to the folder, everything else is automated.

native tide
#

I am really interested in web development but im kinda a beginner in python at what point is a good point to start using django?

vagrant adder
#

I would recommend flask

#

To learn how to figure stuff

#

In django you do stuff only with one way

#

In flask you can do stuff with 3/4 ways

rigid laurel
#

Being limited to one good way is often better than being forced to figure out the best of many ways. A rigid structure I think is more useful when starting out, especially as the Django docs include a pretty good tutorial

native tide
#

But do i need a good understanding of python or can i just start now?

vagrant adder
#

I would say learn how functions work

native tide
#

i understand how they work

vagrant adder
#

Since web dev is just a bunch of functions connected to some task

native tide
#

maybe not the most complex ways of them but i can use them

vagrant adder
#

Then i'd say you are ready

native tide
#

alright thanks

vagrant adder
#

I strongly reccomend flask

native tide
#

What is the difference? between flask and django

simple escarp
#

understanding classes is important too

split mirage
#

I ran into a real bad issue friends. Long story short I've been using Edge browser, now my last session will try to open and then edge immediately crashes. This is a known bug that Microsoft never fixed. I would be happy to find if there is a list of URLs from the last session of about 200 tabs somewhere on my computer. Anyone know where to look?

#

If not then perhaps there is a session file that I can export to a different computer to see if the session will open on that one.

#

Can Microsoft sync Edge browser sessions between computers? If so then that might help if I can open it on another computer.

native tide
#

this isn't web development related

#

but I would try right clicking on the icon and scrolling to the history, then selecting a tab that isn't the one that breaks your browser

#

I would also reccomend ditching edge

#

honestly, why do you use that of all browsers out there.

split mirage
#

Hindsight is 2020, I started using Edge because Chrome won't allow you to scroll through your tabs. I open hundreds of them. My last ditch option is to open a private edge session which so far is the only way to get edge not to crash upon starting and then go through the past 3 months of history and try to piece together my last session of 200ish tabs. Not ideal.

native tide
#

scroll through tabs? chrome allows you to

#

can't you go into the settings and say "do not reopen last session"

#

I know chrome, if it crashes, saves the entire session you can open in one click

split mirage
#

The tab bar at the top of Chrome? No they squeeze together, then at some point when you've opened like 300 tabs you can't click on the tabs off screen.

#

Edge is not cool like that, it doesn't even have a session managing extension.

vagrant adder
#

Gg mate

willow fern
#

Hey Guys, I have a problem with my django app. I am in a production environment, when my debug is false i can't collect any files. I already deployed an app in django before and didn't encoutered this problem.. I did collectstatic but still not working. The only thing i changed compared to my previous project is I added an ImageField with upload possibility for the user.

rigid laurel
#

I'm setting up a relatively simple REST API (at most 4/5 different tables in the underlying database) - is using Flask-SQLAlchemy bad?

willow fern
#

Problem solved... noob mistake, staticfiles not defined on my nginx conf ๐Ÿ˜ข

vagrant adder
#

@rigid laurel sqlalchemy can handle way more than 4-5 tables, it's literally only good SQL ORM for flask

#

better than writing raw SQL xD

rigid laurel
#

I wasn't wondering whether it was the best ORM, rather if it was the most efficient way to write a sensible REST API

#

well not sensible, its obviously sensible. Rather a good rest api

vagrant adder
#

yes, it's more than enough

native tide
#

what are good web projects that I can do in Python,
also Django or Flask ?

vagrant adder
#

flask

#

try make image converter

#

but with as little quality loss as possible

native tide
#

Image converter ?

vagrant adder
#

yeah

native tide
#

Can you explain a bit deeper what that program is supposed to do ?

#

From higher to low res ?
effects ?

vagrant adder
#

i send .jpg to a backend and you return me a .png

native tide
#

Oh, so frontend just has upload file and button that triggeres backend magic

#

And in that backend its supposed to do conversion using module ?

vagrant adder
#

yes

native tide
#

then after that ?
I want something that I can work on during school year

#

and until my school starts

vagrant adder
#

umm

#

so

#

try recreating one of big websites

#

like reddit

#

try to make a reddit clone

native tide
#

oh that is damn huge, anything a bit smaller ?
I would like to code apps, it doesn't need to big since I will be picking up a lot of DevOps

#

be too big*

vagrant adder
#

hmm

#

quora,reddit,twitter

#

all follow the same principle

#

try twitch

#

or google drive clone

native tide
#

I could do something related Google Drive clone

#

But uploads stuff to Amazon S3

vagrant adder
#

yeah

native tide
#

or my server

#

anyways what about a blog ?
I need some kind of personal portfolio for my $h1t, I will probably host it on AWS or GCP

vagrant adder
#

hmm

#

yeah, portfolio would be a good idea

native tide
#

How would Flask be for maintaining things ?
Does it require attention or I can slap it on NGINX and hook up CI/CD

#

with bunch of tests

#

also I would probably do double database (Sounds stupid a f but more DevOps practice for me);
SQL for logins and registration + titles of posts
MongoDB containing content of posts

nimble epoch
#

I want to build a web app. Which one is better to do that flask or Django? (Iโ€™m stucked)

vagrant adder
#

@native tide
you can connect it to some CI/CD no problem

native tide
#

Yeah

#

I'll be using Jenkins

vagrant adder
#

also, you are gonna struggle a LOT with separate databases my dude

native tide
#

So just SQL ?

vagrant adder
#

yeah

native tide
#

alright

vagrant adder
#

i'd recommend postgres

#

very fast and open source

native tide
#

Yeah I had that one on mind

#

Yeah I've heard extremely good things about it

vagrant adder
#

fast af boi

native tide
#

Even though I use MySQL for my local Gitea instance

#

I dislike Github a lot

vagrant adder
#

also, i'd recommend an actual server instead of nginx

#

why

native tide
#

It lacks features that Gitlab has k8s support, yaml CI/CD pipeline and ability to have local install on your server
I think Gitlab is much better but I don't want to use public ones cause I am afraid of censorship like it happend to Iran

#

Why not NGINX in VM on cloud ?

#

I like idea of load balancing stuff

#

One server in west europe and one in east asia (japan probably)

vagrant adder
#

flask tends to be unstable without actual server

#

gunicorn goes well with flask

native tide
#

WSGI ?

#

I thought NGINX supported it

vagrant adder
#

i think it does

#

let me check

#

yes

#

uWSGI

native tide
#

I would use that

#

And have load balancer

#

on eu-west-2 and ap-northeast-1 instances on AWS

vagrant adder
#

also, you can have unlimited private repos on gitlab

native tide
#

I know that

#

I just like using local install, I'll probably hook up CI/CD to clone it to Gitlab

vagrant adder
#

๐Ÿ‘Œ

native tide
#

I would be pissed if my account god erased cause of politicians

#

Like with Iran and Github

vagrant adder
#

lol

native tide
#

Imagine work that was wasted, all those PR's, Issues and Wiki's

#

I would generally be pissed af

vagrant adder
#

damn

#

aight

#

gotta go

native tide
#

cya and thanks 4 help

vagrant adder
#

ping me if you have more questions

native tide
#

k

calm solar
#

whats the most efficient way of getting a user based on the active domain? foo.bar.com, bar.com, www.bar.com all indicating user ~4 is the account to pull preferences from? i'm using latest python/django.

vagrant adder
calm solar
#

?

native tide
#

Is php included in this channel?

#

If so

#

Can anyone help me with making a video sharing website (eg. youtube, vimeo, daily motion, ect)

vagrant adder
#

Not really php

#

Frontend and python

native tide
#

@vagrant adder Hey, quick question, what else RDBMS should I learn except PostgreSQL, I've been wanting to get into more systems alongside PostgreSQL like MS SQL or Oracle Database ?
Are they all same in terms of features or they are different

vagrant adder
#

Nowdays, postgres is GOTO

#

You should really use it except you have a BIG reason not to

#

Maybe learn some NOSQL

#

Firebase/mongo

native tide
#

MongoDB ?
Tbh I am bigger fan of SQL cause of syntax and ease of data structure

#

and manipulating data in tables

vagrant adder
#

Yeah, then postgres is a must

native tide
#

I know that

#

but is it worth picking up basics of MS SQL or Oracle DB ?

#

Both are free

vagrant adder
#

Mongo is used a lot in containerised systems

#

Not really

#

Not used at all

native tide
#

oh ok

#

What IDE is good for supporting my selection of langs : Python, Ruby, Go, YAML and SQL

#

oh and JS

vagrant adder
#

Firebase is used a lot in cloud hosting, and mongo in containerised applications

#

IDE?

#

Hmm

#

For go there isnt really other options than GOLAND

native tide
#

IDE ?
Development environment

#

like Pycharm

#

oh

#

I don't have money for that

#

tbh

vagrant adder
#

Vscode is okay for everything above, but for go GOLAND

#

Then try vscode too

native tide
#

I am 16 year old still learning, hopefully I'll get enough money for Goland

#

and Pycharm

vagrant adder
#

Try vscode

#

It has excellent debugger and linter support

native tide
#

Alright,
I've been mostly writing in Vim (I don't like tbh and had paper with keybinds)

vagrant adder
#

Lol

native tide
#

I prefer 4 letter cancer named Nano

#

oof

vagrant adder
#

Try micro

#

I'm loving it for fast editing files

proper hinge
#

PyCharm is free

#

IntelliJ IDEA can support all those languages with plugins I believe, but typically some features will be missing compared to their IDEs which are specific to those languages

#

Probably it's the only IDE that can support all those languages

#

maybe Visual Studio? I know it supports some of those but not sure about all

tough star
#

How do I change the collapse background color in Bootstrap 4?

vagrant adder
#

just change it normal in css

#

like you usually do

#

if it won't change, add !important tag

#

so

body {
  background-color: red !important;
}
simple escarp
#

i like vim, but if you don't like it, use something else, by all mean, vscode is all the rage these days

#

if you know sql, unless you need to be an expert on a particular system, most sql things should be mostly the same, so i would care only if you try to get a job that use them. Sqlite is cute and used in a lot of systems (from phones to cars, to browsers, to well, everything, this thing is literally used everywhere), it's probably good to know enough to know how bad mogno is, and probably to try other schemaless databases, but sql is getting a lot of love again after people really overbought the nosql hype.

#

oh, and don't worry about being ยซstill learningยป, you are never going to be done learning ๐Ÿ˜ƒ

ruby palm
#

Hi

#

What are responsive grids for?

#

For example

frigid egret
#

@Void#0324 Please ping next time when you reply to a message that's 40 minutes old. I already gave up looking in this chat after ~20 minutes. Found solution myself but it took me a long time.

#

@ruby palm From how I get it, it's a grid system for elements on a web page. There are multiple systems like that one.

frigid egret
#

Hi all!

#

Need some help with setting up multiple languages in Django

#

First, I've given my training project multiple languages in settings.py

#

And now I'm following this guide to let user select their language of choice.

#

So far I've only made it visible on admin side to test it out.

#

The language changes if I change LANGUAGE_CODE option in settings but won't change based on user choice.

#

Seems like I'm forgetting something but I cannot find it in the article

#

Can I get some assistance here please?

frigid egret
#

I think it may be related to my User model cause I have a custom one.

#
class User(AbstractUser):
    """
    Custom user model.
    """
    phone = models.CharField(max_length=100, unique=True)
    username = models.CharField(max_length=150, unique=False, blank=True, null=True)
    first_name = models.CharField(_('first name'), max_length=30)
    language = models.CharField(max_length=20, choices=settings.LANGUAGES)

    USERNAME_FIELD = 'phone'
    REQUIRED_FIELDS = ['first_name']

    objects = UserManager()

    def __str__(self):
        return self.phone

    @classmethod
    def normalize_phone(cls, phone):
        """
        Remove extra spaces and non-digit chars from phone.
        """
        _normalize_phone = re.compile(r'(\s{2,}|[a-zA-Z]+)').sub
        return _normalize_phone('', phone)


@receiver(user_logged_in)
def lang(sender, **kwargs):
    lang_code = kwargs['user'].language
    kwargs['request'].session['django_language'] = lang_code
willow fern
#

What did you encounter to know it's not working ?

opal radish
#

Does anyone know what the best way to manage a postgres connection pool with flask is

#

And how to make it accessible from blueprint files

vagrant adder
#

What do you use

tough star
#

I've created a simple login with Google using flask.
Since one day ago, I get this error when I try to log in.

('Request limit reached', 429, {'Server': 'nginx/1.10.3 (Ubuntu)', 'Date': 'Tue, 13 Aug 2019 07:01:58 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '33', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET', 'Access-Control-Allow-Headers': 'Content-Type', 'ETag': 'W/"21-tYoIBroDGdB+35cIAOMCdpXfqjI"'})
opal radish
#

@vagrant adder psycopg2

vagrant adder
#

Try sqlachemy

#

It goes well with psycopg2

native tide
#
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

Is there a way to turn this into a class?

class FlaskApp(Flask):
    
    def hello_world(self):
        # ...
vagrant adder
#

I think not

#

If yes, you gonna have a bad time

tough star
#

This is my code:

<div class="list-group-item list-dark-flush"><div class="picker" data-initialColor="{{color}}"></div> {{subject}}</div>

How do I align the "subject" div next to the "picker"?

This is what I get now:

wispy parrot
#

I would set it to a child of it then do this ```CSS
#greenThing {
position: relative;
align-items: center;
}

#

u might have to set left to 0 and right to 0 too

native root
#

float, or flex grid

tranquil steeple
#

Can someone help me create a contact page using Flask?

pearl parcel
#

Hi broskis, anyone using pydantic?

#

Is there a way to convert this:
`class GetGamesResponse(BaseModel):
games: List[Game] = []

async def get_games():
output = []
for game in games.find():
output.append(game)
return GetGamesResponse(**{"games" : output})`

#

into this:
async def get_games(): output = [] for game in games.find(): output.append(game) return [Game](**output))

EDIT a solution came to my mind:
@router.get("/") async def get_games(): output = [] for game in games.find(): output.append(Game(**game)) return {"games" : output}

candid basalt
#

@tranquil steeple it's better to ask your questions directly, like "it tried x and y, and y does not work giving this error". You are much more likely to get a helpful answer that way.

tranquil steeple
#

@candid basalt thanks for the suggestion. Although, that wouldn't have serviced it was more a question of best practice. It required more of a conversation. I got the help I needed anyways. Thanks for taking the time to respond.

magic blade
#

I'm having a difficult time with uwsgi timeouts after upgrading an app from Django 1.9->1.11 and Celery 3.x->4.3, and I think the problem is related to Celery but I'm struggling to debug and fix. Is this the right place to ask for help?

#

some things: i know that celery has all the tasks registered; i know that the server sending tasks can connect to the server running the broker & worker processes (tested via telnet but i do wonder if i need to further troubleshoot this step); tasks run fine in my dev environment in which celery/broker/webserver are all on the same machine.

#

i also know that (at least some) tasks run successfully if called directly and not via .delay(). perhaps checking the remaining tasks for this is another step i need to take

native tide
#

hi everyone, how do i know what is my superuser username and password in django? i clearly forgot my account ๐Ÿ˜

magic blade
#

@native tide if you have cli access you can use manage.py shell to find the username. The password should be encrypted and you probably will have to reset or something. Maybe just delete the old one and make a new super user from the cli

native tide
#

thanks! got it

#

@magic blade

tough star
#

I have this code:

<div class="list-group list-group-flush list-group-horizontal-xl">
                                    {% for subject, color in subjects.items() %}
                                    <div class="list-group-item list-dark-flush" style="align-items: center; display: flex"><div class="picker" data-initialColor="{{color if not color == 'none' else '#03A9F4'}}"></div> <span>{{subject}}</span></div>
                                    {% endfor %}
</div>

I want to make that list going in the next line after 4 items.
How I can do this?
(I'm using bootstrap 4 and flask)

This is what I get now:

native tide
#

anyone know why I keep getting 502 bad gateway on my flask app?

#

using gunicorn/flask/nginx

#

Sometimes it works, sometimes it doesn't

#

sometimes my other app routes fail because of the 502 bad gateway

#

used this tutorial to setup nginx/gunicorn and the supervisor script to get it all running

#

also sometimes my socket connections dont work on my app

#

this only happened when i pushed to production

slender charm
#

I am interning at a startup

#

There's an IoT device that sends data and a django web app that reads the data and analyses it

#

does AWS help with this?

#

or any other cloud service

vagrant adder
#

Not really

midnight kernel
#

@native tide are you using anything involving socketing or spawning new subprocesses

native tide
#

yes

#

im using socket io

#

@midnight kernel

midnight kernel
#

@native tide okay, I ran into a similar problem yesterday involving trying to use a subprocess in a gunicorn flask app. what are you using as far as service workers go?

#

also, have you installed anything like eventlet or gevent or something

native tide
#

yeah im using eventlet

midnight kernel
#

hmm

native tide
#
echo "[program:domalert]
directory=/home/dom/domalert/domALERTV5
command=/home/dom/domalert/venv/bin/gunicorn --worker-class eventlet -w 1 app:app --timeout 90 --reload
user=dom
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
stderr_logfile=/var/log/domalert/domALERTV5.err.log
stdout_logfile=/var/log/domalert/domALERTV5.out.log" >> /etc/supervisor/conf.d/domalert.conf```
#

thats my supervisor conf

#

command=/home/dom/domalert/venv/bin/gunicorn --worker-class eventlet -w 1 app:app --timeout 90 --reload

midnight kernel
#

from what i can gather (based on my problem yesterday), its happening cause gunicorn's master process is getting confused and intercepting signals from sockets/subprocess and treating them as if they are its workers

native tide
#

hmm ok

midnight kernel
#

i havent come to a solution yet unfortunately.

native tide
#

oh damn

midnight kernel
#

yeah it was ridiculous. have you tried looking at the system logs when the crash occurs?

#

like, the syslog file in /var/log

native tide
#

Yeah I did

#

lemme paste it here

#

hang on i'll get back to you in a bit

midnight kernel
#

okay

#

(just tag me if its later and i forget to answer ha)

native tide
#
dom@domalert:/var/log/domalert$ cat domALERTV5.err.log
[2019-08-15 17:23:08 +0000] [17391] [INFO] Starting gunicorn 19.9.0
[2019-08-15 17:23:08 +0000] [17391] [INFO] Listening at: http://127.0.0.1:8000 (17391)
[2019-08-15 17:23:08 +0000] [17391] [INFO] Using worker: eventlet
[2019-08-15 17:23:08 +0000] [17394] [INFO] Booting worker with pid: 17394
[2019-08-15 17:24:22 +0000] [17394] [ERROR] Error handling request /socket.io/?EIO=3&transport=polling&t=MoMJkJI&sid=737e8ca231114691a46668dbd7e2f6e2
Traceback (most recent call last):
  File "/home/dom/domalert/venv/lib/python3.6/site-packages/gunicorn/workers/base_async.py", line 56, in handle
    self.handle_request(listener_name, req, client, addr)
  File "/home/dom/domalert/venv/lib/python3.6/site-packages/gunicorn/workers/base_async.py", line 107, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/home/dom/domalert/venv/lib/python3.6/site-packages/flask/app.py", line 2463, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/dom/domalert/venv/lib/python3.6/site-packages/flask_socketio/__init__.py", line 46, in __call__
    start_response)
  File "/home/dom/domalert/venv/lib/python3.6/site-packages/engineio/middleware.py", line 60, in __call__
    return self.engineio_app.handle_request(environ, start_response)
  File "/home/dom/domalert/venv/lib/python3.6/site-packages/socketio/server.py", line 534, in handle_request
    return self.eio.handle_request(environ, start_response)
  File "/home/dom/domalert/venv/lib/python3.6/site-packages/engineio/server.py", line 369, in handle_request
    jsonp_index=jsonp_index)
  File "/home/dom/domalert/venv/lib/python3.6/site-packages/engineio/server.py", line 566, in _ok
    b64=b64, jsonp_index=jsonp_index)}
  File "/home/dom/domalert/venv/lib/python3.6/site-packages/engineio/payload.py", line 19, in encode
    encoded_packet = pkt.encode(b64=b64)
AttributeError: 'NoneType' object has no attribute 'encode'```
#

@midnight kernel

midnight kernel
#

ah, gotta love when there errors are wonderfully ambiguous.

#

is it happening with every endpoint that uses the websockets or just specific ones?

#

ive read a bunch about how high cpu intensive tasks sometimes make all of the gunicorn socketing stuff start throwing a tantrum

#

i think in socketio theres a parameter you can pass to the constructor, like a logger param or something you can set to True to get more details on the websocket itself

native tide
#

hmm ok

#

i mean i just have one socket endpoint meant to establish a connection

#

and emit a event

#

i dont have the socket io reverse proxy in my nginx

#

i'm yet to try these solutions tho

midnight kernel
#

yeah im pretty sure you need to configure that in nginx. my problem isnt with socket io specifically, but with spawning a new subprocess to call a bash script, but the cause of the problem seems similar (getting a socket error)

#

its possible that without the configuration, its sending the socket io request to the main listening port

native tide
#

yeah it seems like its trying that

#

becuase its saying it wasnt expecting a 200 response

#

i think only normal app routes return 200 reponses

midnight kernel
#

yeah a 200 response is not something a websocket should return lol

#

in the 100 range is for websockets

#

(i think)

turbid fox
#

Has anyone explored integrating interactive matplotlib figures into Django?

native tide
#

@midnight kernel what does your nginx file look like?

keen sphinx
#

probably a silly question, and I don't know if I should ask here or in #databases

#

do search forms that pop up suggestions perform a query to the database every time, or do they have a cache for this?

#

like this, I mean

#

I don't know much about databases, so if there was a cache for this I couldn't even guess where and how

terse arrow
#

someone firm with XPath?

#

I have a XML like this:

<Asset ID="PB_106682" UserTypeID="ProductImage">
  <AssetPushLocation ConfigurationID="AP_SHOP_ProdImg_720">Produktbilder/720/PB_106682.jpg</AssetPushLocation>
  <Values>
    <Value AttributeID="asset.pixel-height" UnitID="pixels">531</Value>
    <Value AttributeID="asset.size">1986965</Value>
    <Value AttributeID="asset.format">EPS (Encapsulated Postscript application)</Value>
    <Value AttributeID="asset.preview-format">TIFF (Tagged Image File Format image)</Value>
    <Value AttributeID="AP_SHOPS">1</Value>
    <Value AttributeID="asset.width" UnitID="mm">75,01466666666666</Value>
    <Value AttributeID="asset.filename">106359.eps</Value>
    <Value AttributeID="ATTR_AssetPush_site">1</Value>
    <Value AttributeID="asset.mime-type">application/postscript</Value>
    <Value AttributeID="ATTR_Asset_Marke">something</Value>
    <Value AttributeID="asset.profile">Photoshop, ICC color</Value>
  </Values>
</Asset>

and via an XPath, I want to get rid of every value, except the asset.mime-type

tough star
#

I've created a sortable list using jQuery UI's sortable function.
In my flask app I can get the order of the list by ajax but I don't know how to set the order on the html.

$(function(){
    $('#draggable-cards').sortable({
        handle: '.move-button',
        axis: 'y',
        animation: 200,
        update: function(event, ui) {
            var postData = $('#draggable-cards').sortable('serialize', {key: "id"});
            $.ajax({
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify(postData),
                dataType: 'json',
                url: '/_save_order'
            });
        }
    });
})
@app.route('/_save_order', methods=['POST'])
def _save_order():
    data = request.json
    x = data.replace('id=', ', ').replace(', ', '')
    y = x.split('&')

    me = google.get('userinfo').data
    with open('data/settings.json') as f:
        settings = json.load(f)

    settings[str(me['id'])]['order'] = []
    settings[str(me['id'])]['order'] = settings[str(me['id'])]['order'] + y

    with open('data/settings.json', 'w') as f:
        json.dump(settings, f, indent=4, sort_keys=True)

    return str('')
vagrant adder
#

@tough star

if request.method=="POST":
    saki = do_something(request.get_json())
print(saki)
return saki
#

That will return posted json back to html

tough star
#

But how I can use that json to set the order in the html?

#

@vagrant adder

vagrant adder
#

Order?

#

Defne order

tough star
#

Example:

  • List element 1
  • List element 2
  • List element 3

With my code, if I move an element, I save in the json file the current order of the elements.

#

I don't know how to restore the order of the list (html)

vagrant adder
#

Restore?

#

Umm

#

So you remove one element

#

And later you want to revert the item

tough star
#

No

#

I have that list.

vagrant adder
#

Okay

tough star
#

I can sort the elements thanks to jQuery UI sortable

vagrant adder
#

Okay

tough star
#

I can save the order after I sorted the elements

open forum
#

@tough star When you first load the page with the list, you want to retrieve the stored ordering from the server and render the list with that order?

tough star
#

Yes

vagrant adder
#

Ah

#

jQuery and vanilla js

tough star
vagrant adder
#

For every tr you can make another for loop

tough star
#

tr?

vagrant adder
#

table row

tough star
#

oh ok

#

What I can do for my sorting problem?

vagrant adder
#

Let me get home then i'll try to make something

tough star
#

Ok thanks ๐Ÿ™‚

tough star
#

@vagrant adder Did you found something?

vagrant adder
#

aight

#

you retrieve list order from backend and want it sorted

#

your best bet is to clear the parent div/table

#

and use javascript to rebuild that div/table accordingly to the order

tough star
#

But how? ๐Ÿ˜ฆ

vagrant adder
#

look how js handles DOM elements

#

w3schools

native tide
#

Anybody here know load balancing with Nginx?

verbal ibex
#

I'm attempting to setup nginx conf to serve flask via uwsgi, but not sure what preferred way is.

#

A few tutorials have slightly different ways.

native tide
#

hi, all. how can i get django-simple-bulma to work in jinja2?

zealous igloo
#
data = JSONField()
#

so with the models i have a variable set to that and if i want to send a PATCH request to the view for that how can i make it so taht it only updates a single area within that data instead of completely overwriting the JSONField?

remote anchor
#

I'm about to make my first website. I wanted to use Python. Wish me luck! So excited. Using the Flask framework.

zealous igloo
#

u got this!

remote anchor
#

Thanks, @zealous igloo ! What are you working on?

#

Let's make the next biggest Social Network!!!

zealous igloo
#

working on website with django that lets u store information and stuff on ur favorite tv shows it's mostly just for practice with http requests and getting feet wet with django

#

@remote anchor lol that's huge

remote anchor
#

Good luck on your TV show website! You'll be a professional dev in no time.

And we could TOTALLY make the next Social Media website. I wanted to make a social hub where it has built in translation and language exchange tools. I used to use an app called HelloTalk, but the management is off and I dislike the business model.

zealous igloo
#

lol hopefully i can become a professional dev soon. adnd niiicceee sounds like good idea but really hard with the translation stuff

vagrant adder
#

@verbal ibex
Most preferred way is with actual server

#

Gunicorn or something similar

native tide
#

Hi guys I have a problem with total count of items using django framework

#

In the html Iโ€™m using the tag count to get the total number of the items but it depends on the paginator size

#

If my page is paginated to contain 5 elements and in the db there are 10 elements the tag in the html will give me 5 elements

#

What should I do to get the total of 10 even the page is paginated

#

By the way Iโ€™m using class based views

abstract basin
#

I am using Vagrant in Windows 10.

I am in Vagrant ssh and have activate virtual environment for Django app

Now, I want to setup pycharm to use that virtual environment as wel..

In here, I am not able to figure out the path /home/vagrant/virtualenvs/project/bin/python3

Suppose I get this path in vagrant ssh, then where is this located in My Windows, so that I can use it for pycharm virtual env activation.

Below is the accepted answer.

https://stackoverflow.com/questions/26791893/how-to-setup-pycharm-to-use-virtualenv-in-vagrant-virtualbox-remote-interpreter

Snippet of Answer:


That worked nicely. I can even use the PyCharm interface to install packages into the virtualenv on the Vagrant VM.```
keen sphinx
#

this line, in nginx.conf: include /etc/nginx/mime.types;, which grabs the mime.types file, what is it for? is it to add the proper HTTP header every time nginx has to respond a request?

verbal ibex
#

Is there any magic that needs to happen on the Flask server side to getting Stripe's checkout embed working? I copy pasted the script and checkout button, but the button doesn't take me to the checkout

native tide
#

is it possible to mask a server ip address with a domain, while also not disabling the mobile site of the web page?
because when i mask the ip, and access it on my phone, it shows the desktop version

keen sphinx
#

I don't know about the issue, but it sounds like something related to the proxy server configuration

feral root
#

hello

#

I was using pythonanywhere to get started

#

but they limit chronjobs to once per hour for paid users

#

i need to do once every 2 minutes

#

is there a better site?

vagrant adder
#

For free?

#

Nope

timid arrow
#

well, you probably can make use of AWS free tier for a while

feral root
#

not for free

#

i don't mind paying

#

I was going to pay for pythonanywhere to get mogodb access

#

but then I realised i would be wasting money

#

if I can only do 20 chronjobs a day

rigid laurel
#

Could you not just rent a vps from ovh? It's only like 3ยฃ/mnoth

#

The config you need to do might be annoying, but it's a 1 time thing and useful to know

feral root
#

that has a public accessible web interface? python and connection to mongodb?

rigid laurel
#

Ita just a fully fledged Linux server

#

So yeah kinda

dusk trellis
#

who creates websites with python

#

just curious

turbid fox
#

lots of people

#

lots of companies use Django and other python web frameworks

#

lots of Applications use Django REST

#

Instagram uses Django

vagrant adder
#

@dusk trellis
Me

#

And lots of people

#

And companies

dusk trellis
#

@vagrant adder Why wouldn't they use HTML or Java or JavaScript to create websites what does python bring that is exclusive. Java script makes websites pretty and HTML actually makes the website. What is python use that is so valuable.

vagrant adder
#

Well, python is used for backend

dusk trellis
#

Data bases with libraries ?

vagrant adder
#

Html,css and js is used for things you actually see

#

Yes, databases and data management

dusk trellis
#

oh okay

#

what do you use python for. Storing encrypted passwords, user personal info etc?

vagrant adder
#

Yes

#

Managing sessions, database management etc

dusk trellis
#

okay

#

Do you use an FTP when your using python like using it in a plugins folder or something?

#

@vagrant adder

vagrant adder
#

?

#

Yes, https

dusk trellis
#

No I mean like when creating a website do you use an FTP to access server files and use python plugins

vagrant adder
#

Ah

#

Yes

#

I ssh into my server

dusk trellis
#

interesting

vagrant adder
#

That way i can fiddle with server

dusk trellis
#

I only use .jar files when I work on servers

vagrant adder
#

In my internship company i used to had physical access to the server

#

Like a big cupboard

dusk trellis
#

oh

#

when I work with servers I am at home on my pc logged into file zilla lol

vagrant adder
#

Lel

brave otter
#

Anyone good w/ serialization in django know if it's possible to serialize a model to JSON and descend to foreign keys as well? So if I have a model with a FK to another model, serializing it w/ the django core serializer just serializes the foreign key to its primary key. Instead I'd like to descend and serialize all that model's fields also.

nova tapir
#

Anyone around willing to briefly discuss some json/data structure info?

cursive cairn
#

Quick question
Whats the best solution for plotting > 80k points on a map and dynamically changing points in real time?

tardy nova
#

@brave otter try mapping it to a dictionary and then using the json.dumps function

vagrant adder
#

@nova tapir
Sure

gleaming herald
#

For production what are the alternatives to flask

#

Something that is able to handle huge amount of load

#

I know one is Sanic

#

anything apart from this too

#

that would be efficient af.

vagrant adder
#

django?

#

also, flask is totally okay for production

#

but with dedicated webserver

#

like gunicorn

latent coyote
#

how do i know whether to use flask or django or electron?

#

what even is electron can i combine electron with django or something - im new to webdev

rigid laurel
#

Electron is a way to make desktop apps using JavaScript. It can be combined with Django/Flask if you design your backend Django/Flask as a REST based service

#

Choosing between Flask or Django depends on quite a lot of different things - Electron doesn't really compete with either and is far more likely to be used in conjunction with either

latent coyote
#

does node.js compete with django and flask

vagrant adder
#

not node, but express.js(web framework)

surreal thicket
mortal fern
#

@surreal thicket Thanks, looks like this is what I was looking for. seems I can just use a link to load BootStrap's CSS, then anything I wanna modify/override I can just load my own CSS touching only what I wanna change after Bootstrap

gleaming herald
#

@vagrant adder How do I choose a framkework

#

I only want to create a scalable API so

#

should I go with flask

#

or tornado

vagrant adder
#

i have never used tornado

balmy forge
#

for async, sanic and tornado are great choices

#

If you just want a simple and lightweight framework like flask, go with sanic - it is light and pretty fast

gleaming herald
#

do you have any idea

#

with sanic

#

its pretty new

#

so I would not be able to find resources if I get stuck

#

@balmy forge

balmy forge
#

sanic isnt new

gleaming herald
#

Yes I did

balmy forge
#

It's a favourite of many, it's almost identical to flask

#

And it's pretty fast

gleaming herald
#

It's not used by many

balmy forge
#

github says otherwise

#

If you look at the amount of stars and forks it has

gleaming herald
#

okay

steel tiger
#

With flask-marshmellow + sqlalchemy, how do I build a proper schema that hides a password?

#

I have 3 fields for a user model that look like: py id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(255)) password = db.Column(db.String) And I would like to hide the password when returning a schema

unborn terrace
#

@steel tiger define โ€œhiding a passwordโ€

steel tiger
#

Currently it's just this py class UserSchema(ma.ModelSchema): class Meta: model = User

#

Remove the password field from returning from the schema

#

New to marshmallow, first time using it

unborn terrace
#

Then, simply define two schemas, one for creating an user, one for retrieving/displaying an user

steel tiger
#

Already done

#

What do you think the hashed password is there for :P

#

(Using bcrypt)

#

What would a simple schema look like? Can't figure out the methodology of schemas

unborn terrace
#

So you'll have

from marshmallow import fields, Schema

class CreateUserSchema(Schema):
    username =  fields.Str()
    password = fields.Str()

class UserSchema(Schema):
    id = fields.Integer()
    username = fields.Str()
#

You'll use the first one to create an user (in user registration view for instance), the second one to display it (when an user retrieves its information for instance)

steel tiger
#

Using flask_marshmallow fyi, will it be the same with fields?

unborn terrace
#

They'll probably be similar, I do not know the details of flask_marshmallow, but it would not be very different imo

steel tiger
#

๐Ÿ‘

#

Using sqlalchemy so it may be a little different in that part

unborn terrace
#

The concept you have to grasp is that schemas are โ€œa way to represent dataโ€œ, you can (and often should) use multiple schemas for the same data model

steel tiger
#

Yeah

#

Ahh I see

#
class UserSchema(ma.Schema):
    class Meta:
        fields = ("username",) ```
#

That's neato

unborn terrace
#

๐Ÿ‘

steel tiger
#

Thanks :)

#

I have been using flask-restful for a while and reqparse doesn't cut it

steel tiger
#

Wow, using webargs + marshmallow is really nice

#
class UserApi(Resource):
    args_id = {"id": fields.Int(required=True)}
    args_make = {
        "username": fields.Str(required=True),
        "password": fields.Str(required=True),
    }

    @use_kwargs(args_id)
    def get(self, id):
        user = UserModel.query.get(id)

        if user is None:
            return {"status": "not found"}, 404

        return {"status": "success", "data": user_schema.dump(user)}, 200

    @use_kwargs(args_make)
    def post(self, username, password):
        new_user = UserModel(username=username, password=password)

        db.session.add(new_user)
        db.session.commit()

        return {"status": "success"}, 200
#

So compact and readable

#

Oh geez, i'll have to implament authlib

#

Or I could just cheat and use the api alongside the webapp

magic blade
#

gonna try asking about this again; I'm trying to debug some issues in a setup where a server running django / uWSGI sends tasks to another VPS running the worker processes; recently upgraded Django 1.9 -> 1.11 and Celery (something, i can look it up if it matters) -> 4.3, and it introduced a lot of errors that appear to reside in the communication between the web and worker VPSes

#

more specifically i'm not 100% sure but it does appear that uwsgi processes which call task.delay() or similar, are getting stuck waiting for some kind of response from the worker which either does not come, or comes too late.

#

all of this is running on python 2.7; of course we are trying to migrate to python3/django2 by the end of the year, but, y'know. only a few steps at a time.

junior cloak
#

@gleaming herald Starlette is currently the fastest async python web framework. its creators also created the ASGI spec it runs on, which other things are starting to implement as well, including django. so not bad to familiarize yourself with it

surreal thicket
#

is ASGI a significant improvement over WSGI?

#

every time i hear "fastest" i think "with what caveats"

proper hinge
#

To me it wasn't a difference of speed it was rather "this can be async and this other thing can't"

#

Well there's probably some way to use WSGI asynchronously but I haven't seen anything

surreal thicket
#

what does sanic do?

proper hinge
#

It uses ASGI I believe

#

Ok well that's not entirely accurate

#

It can use ASGI, but also has its own webserver and gunicorn support

junior cloak
#

@surreal thicket ASGI is essentially the successor to WSGI. you've already left WSGI in the dust if you're using any sort of true async web framework/server and do things like run websockets properly. it's just that until recently, all the packages that were able to do this were doing it their own way

#

ASGI is an actual spec and everything that uses it can be bolted onto anything else that uses it with a one-line command. that aside, the web framework it powers (Starlette) just happens to outperform the others

#

there's nothing wrong with sanic and in many ways it is nicer to work with than starlette and more mature

#

aiohttp is a step down from there in that it's even more mature but also among the slowest of the async frameworks while also not being quite as easy as sanic to work with most would say

#

but theyre all fine if one just works with your brain better than the others. provided the performance difference isn't something you are concerned about. something like tornado, though, is something you should probably try to forget exists

balmy forge
#

I actually found aiohttp pretty fast, benchmarks between aiohttp and tornado and sanic yields amazing results in aiohttp leading, but simply because you will need to implement everything again with aiohttp

junior cloak
#

i just also like starlette because though the newest it is currently moving incredibly fast, and since they wrote the underlying spec and a bunch of other tools i also use, the interaction between them (and eventually even things like django) is pretty great

#

aiohttp is definitely not slow. it's nice to use, the most mature, has been around a while, far better than using not async, etc

balmy forge
#

Oh wow, I did not know about this, many thanks for sharing

junior cloak
#

but if you are building something where squeezing every drop of performance out of your app is a potential big deal for costs and whatnot, starlette obliterates it

#

(for many practical uses)

#

1 and 2 on that list are starlette and uvicorn. which are both made by the same people, uvicorn being the web server that powers starlette

balmy forge
#

Oh no I completely understand and agree on that

#

I dont see sanic here though

#

tornado being slower than flask is a surprise

junior cloak
#

nobody may have run sanic tests for this site lately but i promise you it's faster than most but not faster than starlette. but you should use whatever does what you need and you feel comfortable with

#

sanic can do a lot and has the flask-esque extnesion community

balmy forge
#

I've used sanic and benchmarked with it before, so I know how fast it is

junior cloak
#

aiohttp doesnt has nearly as much of that, or anything baked in. starlette has at least the interfaces and mechanisms for you to use for things like auth, app config, graphql, background tasks/queues, etc, stuff you may have to bolt on yourself in other places

#

if you're building a very structured REST API, you ought to look at this: https://fastapi.tiangolo.com

balmy forge
#

Most interesting

junior cloak
#

it's built on top of starlette, but generates for you everything you need for a type-enforced REST API including the swagger pages and tests and such

balmy forge
#

Why didnt I talk to you before I build my backend lol

junior cloak
#

(the guys who made starlette are also respondible for apistar, which does the autogenerating swagger/openapi stuff, and are also the guys who made and maintain django-rest-framework which they based it on)

#

everyone has different needs, and ive only had my own experience

#

but part of that experience was going all in on async very early on and having built very high-traffic things using all of these frameworks and shooting myself in the foot plenty of times

#

the move from aiohttp to starlette for our main backend service that lots of users remain connected to via websockets and most clients are pushing messages to pretty frequently... the move gave about a 3-4x increase just instantly of how many concurrent ws connections it could reasonably manage on the same server specs with the same or better response times

#

for the types of apps we're building, that kind of stat is not insignificant in our survival because it's the heaviest service and is now servicing more users with lower costs

#

but i know that's not everyone's use case, or most peoples', and sticking to any of these async, non-tornado options that works best for you isnt a bad idea

balmy forge
#

@junior cloak wanna say thanks for telling me about fastapi, it's really fantastic and a pleasant to work with. It does fit what I need perfectly for a python - react project

junior cloak
#

@balmy forge haha perfect! everyone has different needs and no one thing is best for everyone, but there's some great stuff out there and it's nice when you find the right one

sturdy sapphire
#

fastapi looks great.. im going to bookmark that page and get back to it

junior cloak
#

i'm working heavily with graphql now so fastapi isn't something i'm using much, but man i would've been all over that 3ish years ago doing all that work manually. hell of a project though and it did convince me to start using pydantic for a ton of things and dive into the type annotation world more than i had been

#

there should really be a better way to find some of these things. like if awesome-python (or any of the "awesome" lists) were not just kept up to date but if you could just click like a few tags that are your top priorities or use-cases and have it spit out some options that are best with that combination

#

i was looking at specs earlier for a piece of video editing software, and instead of just the usual "system requirements" that most software has, it was a very large table, where the primary field was the sort of video work you'll be doing, another field was the format of your source material, and the next fields were the recommended computer specs to best service that exact combo. thought that was pretty smart

#

anyways, stray thought. enjoy the cool web frameworks 2019 has given us

steel tiger
#

I would like to delete a user but when I do, i'd like to delete all of it's relationships. How do I do this?

#

(As in a user has 100 posts, how would I delete them posts cleanly if the user purges their account)

steel tiger
#

Also, how do you send a file (zip specifically) into a flask-restful api. Using webargs

flint breach
#

on delete = cascade

#

for the first problem

polar wasp
#

@steel tiger i'm not sure deleting is necessarily the right thing to do to a "post" when a user is deleted

#

if these posts are part of conversation threads, just deleting can make it unclear what people are replying to

steel tiger
#

True

#

I could orphan them to 1 "deleted" user

polar wasp
#

you may want to delete the text and/or the association to the username for privacy purposes, but that isn't necessarily possible to do as a simple sql constraint

steel tiger
#

So I have to loop through and "delete" them with a custom helper func?

#

Thinking how discord has it

polar wasp
#

with a well-defined data schema you could probably do it as a sequence of sql statements within a transaction

#

no looping necessary (the way discord does it is extremely inefficient because it's not an intended feature beyond the ability to delete individual posts or clear whole channels)

steel tiger
#

I could loop through the users posts and call a helper func contained in the post model

polar wasp
#

you really shouldn't need a loop

steel tiger
#

That patches it's id to a special user

#

What should I do?

polar wasp
#

whatever you decide for the design, you're doing the same thing to every post, it can almost certainly be an update with a where clause

steel tiger
#

Oh I'm using sqlalchemy

steel tiger
#

flask-sqlalchemy even

#

Where it's not favoured to use pure sql

#

Not sure if this is a thing py from sqlalchemy.sql.expression import bindparam stmt = addresses.update().\ where(addresses.c.id == bindparam('_id')).\ values({ 'user_id': bindparam('user_id'), 'email_address': bindparam('email_address'), })

polar wasp
#

er that isn't really the same scenario, but sqlalchemy apparently does have facilities for updates with where-criteria instead of single model object updates

steel tiger
#

Yeah

polar wasp
steel tiger
#

You don't really have them in flask-sqlalchemy

#

It's more x number of model classes and you do it all by changing an object from the model class then commiting it

polar wasp
#

I really doubt that

steel tiger
#

I'll see if there is an equivilant

polar wasp
#

by using query.filter_by(...).update(...)

steel tiger
#

Yeah I know that

#

Just thinking in terms of bulk

#

I have devised a scheme in my head to do it but i'd have to loop over all models in a relationship

polar wasp
#

that probably isn't necessary and is going to be a performance bottleneck if you have a large number of records to update

steel tiger
#

Yep

#

I mean

#

I could rename the user to "DELETED USER" and purge all account info

polar wasp
#

i'm almost certain sqlalchemy/flask-sqlalchemy provides you the tools to make the DB execute a single update statement that updates them all - an ORM that couldn't would be pretty worthless

steel tiger
#

Yeah

#

May have found my saviour

#

Oh

#

Just a simple hidden pattern..

#

I guess that could work

#

Just render as deleted user

#

And blank account info

polar wasp
#

keep in mind also that you may have GDPR obligations or similar with regards to storage of data a user intends to delete

#

i'm not a lawyer though

vast bane
#

hey, can someone help me find websockets of fb live video for a project, pls ping me if u know anything about it

steel tiger
#

@polar wasp Yeah, just a testing api currently

#

I need to read up on gdpr actually

rigid laurel
#

Anyone have any experience with a Flask/React stack?

If so, what is the easiest way to pass an auth token between containers? Passing it down the tree, Context API, or shall I just accept that I need to use Redux?

vagrant adder
#

ask @normal karma he works with flask and react

barren path
#

Yoooo

#

I have built a flask app in one file but its like 600 lines and I want to split it into multiple files

#

Does anyone have a good strategy/way/tutorial to do this?

#

appreciated.

flint breach
#

take a look into the mvc pattern

rigid laurel
normal karma
#

@rigid laurel Depends on your component structure, and where you need to access your token. If you want to access the token in only one component, fetch it and put it in the component's state (or state hook). If you need to access it in multiple components, you have a few options: find a common parent component (you can do it in root App component), to avoid callback madness, and just pass the token to child components via props. That can be really tedious, so I'll advise you to use Redux. I've, personally, was avoiding to use Redux because I just didn't understand it at first, but I picked it up very fast. Also, it synthesizes with Functional Components really well if thats your thing. I strongly suggest you take a look at Redux, it will make your life a lot easier.

#

Its a long response, take your time with it

rigid laurel
#

I think you're almost certainly right and I guess I'll get started with Redux. Thanks for the detailed response

normal karma
#

Glad I could help :)

brave otter
#

hey everyone

#

I'm trying to figure out how to sort an html table based on some nested data structures, for example:

results = {
  "A": {
    "is_data": [
        {key1: val1, key2: val2,}
    ],
    "bs_data": [
        {key1: val1, key2: val2,}
    ],
    ...
  },
  "B": {
    "is_data": [
        {key1: val1, key2: val2,}
    ],
    "bs_data": [
        {key1: val1, key2: val2,}
    ],
    ...
  },
  ...
}

I'd like to be able to sort A and B based on things like val1 and val2.

#

for now each of the *_data items will only have one object in it

#

my goal is to have A and B reorder themselves based on some of the values in the sub-objects. So if A['is_data'][0]['key2'] > B['is_data'][0]['key2'] I'd like them in this order, but if not I'd like them flipped.

#

any thoughts? I'm working on it while I wait

#

This might be easier to visualize...I want to sort the keys of results based on things like calendardate, datekey, reportperiod, etc

steel tiger
#

Depends how large it is