#web-development

2 messages Β· Page 225 of 1

wet verge
#

this is not a good menu style. first search another menu styles on the internet

#

after try your codes

onyx lava
#

So in flask, how could I return a page, then wait 3 seconds and then return another page?

#

Or would that be made in pure js

frank shoal
#

after you return a response, you can't change it. You'll need to use javascript

#
setTimeout(() => {
  window.location = "/newlocation";
}, 3000)
dusty haven
#

Anyone here with expertise in Django ???:

plush wigeon
#

Hi guys, I'm new to web dev and I'm building a portfolio website with Django. I'm not good with frontend.. are there any free resources that I can use like templates to make the html/css look nice?

amber ember
#

is anyone aware of an asyncio-friendly password hashing library? Ideally something that supports argon2 that can be awaited

#

passlib seems to be the go-to but I can't find anything suggesting it supports asyncio natively.

#

I'd like to avoid having to write my own async plumbing around it

serene prawn
#

Assuming passlib doesn't hold GIL πŸ€”

native tide
stable bear
#

why is it better to use a storage platform for storing databases, rather than just use the database on a vps like a local machine?

mint folio
#

Yes

#

I don’t know are they the same thing ?

#

Then looks like a heroku problem.

native tide
#

heroku also provides postgresql add-on tho

#

:'

mint folio
#

Yes but these days it’s all automated through CI.

tender oracle
#

Hi everyone, Actually I'm working on Building a Blog web Application using Flask and the problem I faced is on adding a code snippet option to my Editor with Flask-CKeditor
The Editor load and there are no any problem but How to add a code snippest option:
What I did is I Download the CKEditor version 4.17 from here
https://ckeditor.com/ckeditor-4/download/
Then I Did the configration to load the CKeditor locally as below:

app.config['CKEDITOR_SERVE_LOCAL'] = True
and then I copy the ckeditor folder to static folder and load it with jinja as below where I want to use it on the web page.

{{ ckeditor.load(custom_url=url_for('static', filename='ckeditor/ckeditor.js')) }}
I download the code snippest plugin from here
https://download.ckeditor.com/codesnippet/releases/codesnippet_4.17.2.zip
Then I activated as Flask-CKeditor mentioned on their documentation like this

app.config['CKEDITOR_ENABLE_CODESNIPPET'] = True

app.config['CKEDITOR_CODE_THEME'] = 'school_book'
for full code here
https://github.com/Shalabyelectronics/BlogCapstoneProject

Download a ready-to-use Latest Version of CKEditor 4 package.

GitHub

Contribute to Shalabyelectronics/BlogCapstoneProject development by creating an account on GitHub.

dense ridge
#

hello everyone, does anyone have any expereince with datatables from datatables.net?

dusty haven
native tide
#

it's a good one

#

imo

dusty haven
native tide
# dusty haven Ya dude thanks.

This video is a full backend web development course with python. In the course, you will learn everything you need to know to start your web development journey with Python and Django.

✏️ Course developed by CodeWithTomi. Check out his channel: https://www.youtube.com/c/CodeWithTomi
πŸ”— Join CodeWithTomi's Discord Server: https://discord.gg/cjqNB...

β–Ά Play video
#

:")

dusty haven
native tide
#

professional? eh.. no i don't think so

#

but i've used it

#

and i'm pretty much okay with it ig?

dusty haven
#

Ok

frank frigate
#

any idea why i cant put an image into the website? this is my code im basically trying to get a grasp on web dev

from flask import Flask, render_template, url_for

app = Flask(__name__)

@app.route("/")
def home():
    return render_template("index.html")

if __name__ == "__main__":
    app.run(debug=True)
#

this is the index.html code

#
<!DOCTYPE html>

<html>
    <head>
        <title>Learning html baby</title>
        <style>
            img {
                width: 100px;
            }
        </style>
    </head>
    <body>
        <img src="SiteTests\Images\assassin.jpg">
    </body>
</html>
#

just trying to experiment with this and for some reason its just not working

prisma ravine
#

hey guys how can i make the photo and text in same line?

frank frigate
#

i saw a stackoverflow question mentioning the exact same topic, tried using the answer, and it just still doesnt work for me, although something interesting, if i right click on this small little icon in the website

#

and i click save as

#

it actually saves the thingy on a .html file and the pic is displayed correctly if i open that .html file

plush wigeon
#

i'm having trouble understading what RESTful APIs are. Are they just JSON data that is easily accessible over the internet and retrievable through python?

serene prawn
#

api can use json but not use rest at the same time

#

Also iirc REST doesn't mention JSON at all, so you can use any format you like

frank frigate
amber ember
plush wigeon
#

I see. So basically we can manipulate or interact with REST APIs via GET, POST, PUT, DELETE requests?

amber ember
#

yes

#

so a GET to /users is expected to return a list of user objects, while a POST to /users is expected to create a new user

#

PATCH to /users/<id> is expected to partially update an existing user, etc

#

you'll sometimes hear them referred to as CRUD actions

#

create, read, update, delete

plush wigeon
#

hmm so REST APIs are CRUD apps?

#

or i mean you can use REST APIs for CRUD apps

#

or REST APIs are meant for CRUD apps

thorn igloo
#

you can use them for that

plush wigeon
#

I guess REST APIs can be used for a lot of things and I'm just not getting the full scope of it

thorn igloo
#

REST is just a structure for an API

serene prawn
#

But you for example might have endpoints like this:
/auth/sign-up
/auth/sign-in
/transactions/statistics

amber ember
#

in dogmatic REST there's only HTTP verbs on URL nouns. In reality you'll have the occasional "do the thing" URLs like Doctor details above

serene prawn
#

@amber ember You solved your issue with passlib?

amber ember
#

I was just doing some research. Not actual coding yet

#

want to eventually graft something in to a FastAPI back end

plush wigeon
#

so i can have an API endpoint like.. blog/register/

amber ember
#

you can technically have any API endpoint you want πŸ˜„

plush wigeon
#

which register doesn't really pertain to any of the CRUD actions. i guess POST?

amber ember
#

if you're gonna write a blog, you'll probably have posts and comments as your main objects

#

so like...posts/<id>/comments

plush wigeon
#

hmm i guess what i'm referring to is like.. for posts/<id>/comments uses the create action of CRUD to create a comment?

#

or update if the user edits it

#

i guess the end action

#

i don't know if i'm thinking about it the right way though

amber ember
#

GET /posts - return a list of posts
GET /post/<id> - return an individual post
POST /posts - create a new post
PUT or PATCH /posts/<id> - update an existing post
DELETE /posts/<id> - delete a specific post
GET /posts/<id>/comments - get all comments on a specific post
GET /posts/<id>/comments/<id> - get a specific comment on a post
POST /posts/<id>/comments - create a new comment on a post
you may or may not want to let people update comments on posts but if you did it'd be a PUT or PATCH on /posts/<id>/comments/<id>
DELETE - /posts/<id>/comments/<id> - delete a comment from a post

#

PUT/PATCH are sometimes used interchangably as they both mean "update an object"

#

in precise terms PUT is "replace this object" and PATCH is "update this object"

#

but in practice most people aren't gonna care if you use PUT or PATCH for updating an object

plush wigeon
#

ah so basically you'd have to make a function for each one of those, depending on how you want it

amber ember
#

yep

#

Here's some pseudocode that vaguely represents FastAPI

from fastapi import FastAPI

app = FastAPI()

@app.get("/posts", response_model=list[PostViewModel])
def index_posts(db: ObjectThatRepresentsADatabaseConnection):
    return get_posts_from_the_db(db)

@app.post("/posts", response_model=PostViewModel)
def create_post(db: ObjectThatRepresentsADatabaseConnection, post: ObjectThatContainsPostInformation):
    return create_a_post_in_the_db(db, post)

@app.get("/posts/{id}", response_model=PostViewModel)
def show_post(db: ObjectThatRepresentsADatabaseConnection, id: int):
    return get_post_from_db(db, id)

@app.patch("/posts/{id}", response_model=PostViewModel)
def update_post(db: ObjectThatRepresentsADatabaseConnection, id: int, updated_post: ObjectThatContainsPostInformation):
    return update_post_in_db(db, id, updated_post)

@app.delete("/posts/{id}")
def delete_post(db: ObjectThatRepresentsADatabaseConnection, id: int):
    return delete_post_from_db(db, id)
plush wigeon
#

hmm is the FastAPI module necessary?

serene prawn
amber ember
#

You'll want to use some sort of framework, be it FastAPI, Flask, Django/Django Rest Framework

serene prawn
#

You can use anything to build rest api's

amber ember
#

but strictly speaking no, you could write it all from scratch

#

wouldn't recommend it though

plush wigeon
#

ooh

serene prawn
#

Yep, i'd recommend FastAPI

#

Django is hard to customize and it forces you to use it's orm

#

django itself is a bit dated

plush wigeon
#

i am using django to build this site. but i guess i could forego django's Rest API and use FastAPI isntead?

amber ember
#

well if you're already using django then go with that

#

there's a HUGE amount of information out there to help you learn

#

django is an older framework but the ecosystem and community knowledge is massive

#

FastAPI is the new kid on the block, and is making waves. It's all I've written at my job for the last year

serene prawn
amber ember
#

yeah but this person obviously is somewhat newish to this whole thing so if they're already using django I dunno what the benefit would be to them ditching it for FastAPI + some JS framework

serene prawn
#

I wish my team have chosen fastapi instead of django when we started our backend

amber ember
#

if it's someone experienced then yeah, absolutely use FastAPI every time

serene prawn
amber ember
#

I just think FastAPI needs a little more time to get more ecosystem around it for people who are just learning this stuff, but that's just me

serene prawn
#

@amber ember To be honest i don't see any advantages in using django other than built-in authentication, maybe drf has some things like built-in filters and pagination, that's pretty much all

amber ember
#

in this case the advantage is a hell of a lot more learning material to draw from

serene prawn
#

Django ORM is just a hindrance

amber ember
#

true, although I work with plenty of people that curse the name of SQLAlchemy every time you bring it up πŸ˜„

serene prawn
amber ember
#

I've been doing this for multiple decades now and even I struggle with that documentation

#

it's so goddamn dense

serene prawn
#

There's api reference and guides for using different parts of sqlalchemy, it covers most of the use cases

ionic raft
#

Does anyone have experience with deploying docker on digital-ocean? I've got a dockerfile for a Django application I'm trying to deploy that is stalling on build. This followed needing to add a RUN command RUN gunicorn --worker-tmp-dir /tmp Whurthy.wsgi

The central challenge is that there is something DO is doing with builds that doesn't default the tmp directory...which is why this RUN command is needed. I've tried the two following BUILDS

ENTRYPOINT ["gunicorn"]
CMD ["Whurthy.wsgi", "-b", "0.0.0.0:8000"]```
and

ENTRYPOINT [ "/bin/bash", "-l", "-c" ]
CMD ["gunicorn --workers $WORKERS --threads $THREADS --timeout $TIMEOUT --bind :$PORT run:app"]```

Both are failing. DO Support is not replying to this stall on build.

serene prawn
ionic raft
# serene prawn Can you share whole dockerfile?
FROM python:3.8-slim

ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV HOME=/app
ENV APP_HOME=/app/web

RUN mkdir -p $APP_HOME && mkdir -p build/static && mkdir -p build/tmp
WORKDIR $APP_HOME

RUN apt-get -y update \
    && apt-get install -y \
        gcc \
        libpq-dev \
    && rm -rf /var/lib/apt/lists/*

COPY ./requirements.txt ./
RUN pip install -r requirements.txt psycopg2==2.9.3

COPY . .

RUN python3 manage.py collectstatic -c --noinput \
    && chmod 777 $APP_HOME

RUN gunicorn --worker-tmp-dir /tmp Whurthy.wsgi
EXPOSE 8000

ENTRYPOINT [ "/bin/bash", "-l", "-c" ]
CMD ["gunicorn --workers $WORKERS --threads $THREADS --timeout $TIMEOUT --bind :$PORT run:app"]```
serene prawn
#

Why do you need RUN gunicorn --worker-tmp-dir /tmp Whurthy.wsgi?

ionic raft
#

This works locally. However, DO is doing something that is reflected in comments around a known issue on this

ionic raft
# serene prawn Why do you need `RUN gunicorn --worker-tmp-dir /tmp Whurthy.wsgi`?

Because of the aforementioned issue. DO even recommend the use of a RUN command here: https://docs.digitalocean.com/products/app-platform/languages-frameworks/python/django/
Specifically:
Modify the Run Command setting to point to your application. For this example my project is named mysite. So the modified command would be gunicorn --worker-tmp-dir /dev/shm mysite.wsgi.

DigitalOcean

Manage Django apps in DigitalOcean App Platform.

#

So, without that run command the deploy fails to truly work. The known issue is the way DO processes the tmp directory during build.

serene prawn
#

What's the issue though? πŸ€”

ionic raft
#

The application build hangs

serene prawn
#

Hm, on which stage?

ionic raft
#

It still has a spinning wheel 15 minutes later

#

Build

serene prawn
#

Which command in dockerfile?

ionic raft
ionic raft
#

It successfully starts gunicorn

serene prawn
#

Because you're running your gunicorn during build

ionic raft
#

But something is NOT workign

serene prawn
#

So it never finishes

ionic raft
#

Ok. So what do i change?

#

Because this has been all day on this known issue.

#

The dockerfile works locally...but not when deploying to DO

serene prawn
#

I use this dockerfile for django at work:

FROM python:3.9-slim-bullseye

WORKDIR app

RUN pip install poetry==1.1.12

COPY ./poetry.lock ./pyproject.toml ./

RUN poetry run pip install 'setuptools==61.2.0'
RUN poetry install --no-dev

COPY . .
RUN poetry run python manage.py collectstatic --settings main.settings

ENTRYPOINT ["poetry", "run", "gunicorn", "--worker-class", "gevent", "--bind", "0.0.0.0:8000", "main.wsgi"]
amber ember
#

yeah the gunicorn process never terminates

serene prawn
#

Just create a correct entrypoint, your build seems to be ok

#

remove RUN gunicorn ..., remove your ENTRYPOINT and CMD

serene prawn
ionic raft
serene prawn
#

Again

#

Just

#

Don't run your gunicorn when you're building your image

amber ember
#

yeah but doing RUN gunicorn the process never terminates

ionic raft
serene prawn
ionic raft
#

point 7...

#

AND...support directly suggested adding that RUN

serene prawn
#

It's probably references entrypoint

ionic raft
#

Which is why I originally asked for experience with deploying dockerfiles with Digital Ocean

serene prawn
#

Also it doesn't mention docker at all

#

So your "run command" is the command you're starting gunicorn with

#

not RUN in dockerfile

ionic raft
#

When I asked for clarification they didn't reply

amber ember
#

I'm willing to bet they meant "CMD"

ionic raft
#

I really WANT this to work. Django deployment is ARSE

serene prawn
#
ENTRYPOINT ["poetry", "run", "gunicorn", "--worker-class", "gevent", "--bind", "0.0.0.0:8000", "main.wsgi"]
version: "3.9"
services:
  backend:
    build: .
    command: ["--workers", "4"]

I can later add more arguments in docker-compose, docker swarm, k8s manifests or anywhere else

amber ember
#

I thought entrypoint was the script that then becomes PID 1 and CMD is what was actually run by the entrypoint script

ionic raft
#

OK. Good learning...Digiital Ocean's documentation is ARSE

amber ember
#

usually we use tini for entrypoint

serene prawn
ionic raft
#

I love to code...I really detest deployment

plush wigeon
#

\

serene prawn
ionic raft
ionic raft
#

I currently have:

EXPOSE 8000
ENTRYPOINT ["gunicorn"]
CMD ["Whurthy.wsgi", "-b", "0.0.0.0:8000"]```
serene prawn
ionic raft
#

like so ENTRYPOINT ["gunicorn --worker-tmp-dir /tmp"]

serene prawn
#

It's recommended to enclose each argument into string

ionic raft
#

ENTRYPOINT ["gunicorn", "--worker-tmp-dir /tmp"]

serene prawn
#

like this:

ENTRYPOINT ["poetry", "run", "gunicorn", "main.wsgi"]
plush wigeon
serene prawn
serene prawn
ionic raft
# serene prawn ```dockerfile ENTRYPOINT ["gunicorn", "--worker-tmp-dir", "/tmp"] ```

Excellent...so now I have:

FROM python:3.8-slim
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV HOME=/app
ENV APP_HOME=/app/web
RUN mkdir -p $APP_HOME && mkdir -p build/static && mkdir -p build/tmp
WORKDIR $APP_HOME
RUN apt-get -y update \
    && apt-get install -y \
        gcc \
        libpq-dev \
    && rm -rf /var/lib/apt/lists/*
COPY ./requirements.txt ./
RUN pip install -r requirements.txt psycopg2==2.9.3
COPY . .
RUN python3 manage.py collectstatic -c --noinput \
    && chmod 777 $APP_HOME
EXPOSE 8000
ENTRYPOINT ["gunicorn", "--worker-tmp-dir" ,"/tmp"]
CMD ["Whurthy.wsgi", "-b", "0.0.0.0:8000"]```
ionic raft
serene prawn
#

Maybe also update your python πŸ˜‰

ionic raft
#

I'm running python 3.10. I should update to 4.0 at the top?

#

Old dockerfile

serene prawn
#

python 4 πŸ‘€

ionic raft
#

LOL

#

That's the django version

serene prawn
#

yep, python:3.10-slim

#

Also try poetry

ionic raft
#

poetry?

serene prawn
#

It's a dependency management tool for python

ionic raft
#

I just want to deploy this app

serene prawn
ionic raft
#

I will circle back to that. For now, I just need this app running

serene prawn
#

Just saying, it's really great to use

plush wigeon
#

Hmm okay so I'll learn django ORM :d I know basic SQL like creating tables and altering, inserting stuff

ionic raft
#

Im with you...and I really need this app deployed

serene prawn
ionic raft
#

Once I get this app deployed then I can learn more stuff πŸ˜„

serene prawn
ionic raft
ionic raft
#

We're going to deployment!

#

Argh

#

Back to same issue

#
[2022-04-23 23:24:28]   File "/usr/local/lib/python3.10/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
[2022-04-23 23:24:28]     worker.init_process()
[2022-04-23 23:24:28]   File "/usr/local/lib/python3.10/site-packages/gunicorn/workers/base.py", line 142, in init_process
[2022-04-23 23:24:28]     self.run()
[2022-04-23 23:24:28]   File "/usr/local/lib/python3.10/site-packages/gunicorn/workers/sync.py", line 125, in run
[2022-04-23 23:24:28]     self.run_for_one(timeout)
[2022-04-23 23:24:28]   File "/usr/local/lib/python3.10/site-packages/gunicorn/workers/sync.py", line 62, in run_for_one
[2022-04-23 23:24:28]     self.notify()
[2022-04-23 23:24:28]   File "/usr/local/lib/python3.10/site-packages/gunicorn/workers/base.py", line 75, in notify
[2022-04-23 23:24:28]     self.tmp.notify()
[2022-04-23 23:24:28]   File "/usr/local/lib/python3.10/site-packages/gunicorn/workers/workertmp.py", line 46, in notify
[2022-04-23 23:24:28]     os.fchmod(self._tmp.fileno(), self.spinner)
[2022-04-23 23:24:28] PermissionError: [Errno 1] Operation not permitted
[2022-04-23 23:24:28] [2022-04-23 23:24:28 +0000] [4] [INFO] Worker exiting (pid: 4)```
#

This is literally the original error from the very first deployment, that took me down this rabbit hole

#

I really, really, REALLY do not enjoy deployment

serene prawn
#

sec

#

I think you just have to change permissions on your /tmp dir

ionic raft
#

Ouu.;..

#
    && chmod 777 $APP_HOME  && chmod 777 build/tmp```?
serene prawn
ionic raft
#

Nah...that's it.
I'm going to try RUN mkdir -p $APP_HOME && mkdir -p build/static && mkdir -p build/tmp && chmod 777 build/tmp

#

Adding the chmod to the end after mkdir

serene prawn
#

Try using /dev/shm instead of /tmp

#

(no chmod needed)

ionic raft
#

Oh...good idea

#

RUN mkdir -p $APP_HOME && mkdir -p build/static && mkdir -p build/dev/shm

serene prawn
#

You don't have to call mkdir

plush wigeon
#

its to apply for jobs mainly

serene prawn
plush wigeon
#

and to learn more

#

i think i'll use FastAPI after

ionic raft
serene prawn
#

Are you using backend rendering (templates) or are you also using a frontend framework like React?

plush wigeon
#

only backend stuff for now, so i can get solid on it

serene prawn
#

Both are capable

plush wigeon
#

my understanding is very rudimentary and i'm following tutorials to build a django site lol

#

i guess thats what the render() function is in django? when I put in the 'base.html' template in

#

as an argument

serene prawn
#

Yep, you're rendering html template

ionic raft
amber ember
ionic raft
ionic raft
serene prawn
ionic raft
#

In short, I migrated to db in dev online to remove this as an issue

serene prawn
ionic raft
#

In dev I'd run migrate and was working with the online db. Need to run migrate even though db is already built and running in dev app?

#

OH

#

OF COURSEq

#

I need to migrate the docker container~!!!!

#

oH My goodness

serene prawn
#

You should run your migrations when you deploy new version of your application, i use init container for that

version: "3.9"
services:
  backend:
    image: cool-image
    networks: [internal, traefik-public]

  backend-migrate:
    image: cool-image
    networks: [internal]
    deploy:
      restart_policy:
        condition: on-failure
        delay: 10s
        max_attempts: 3
    entrypoint: "poetry run python manage.py migrate"
ionic raft
#

Yes

ionic raft
#

AND, I'm actually OK with that. Finally got through docker deployment phew

#

ALRIGHT! So, now the issue is that css styles have not applied. BUT, the app is uP!

plush wigeon
#

just curious, whats the advantage of deploying your django app through docker?

ionic raft
serene prawn
#

e.g. installing python, dependencies, etc

ionic raft
#

OH MY GOD! SO....I have site up. NOW, I just need to work out why css styles aren't applying. I'm betting I'm missing something related to the setting of the root templates directory!

#

In fact, not even the Django admin css styles are working...odd

#

So...css styles are not applying anywhere in this site...BUT, this is likely about STATIC_ROOT in settings.py. Need to turn off

plush wigeon
#

hmmm so if I used docker to deploy my django app on a website, what steps does that skip?

worn crystal
#

Does anyone have much experience with azure cognitive search? I'm looking into it right now for implementing suggestions and autocomplete and I don't know much about it besides what's in the docs

amber ember
#

also makes local development easier

#

you don't have ot install python or set up the virtualenv

ionic raft
#

OK. My AWS static files aren't being served up in this Django app...

#

So, I can't seem to get static files to display 😦

plush wigeon
#

i see. so if i define python:3.10 in my dockerfile, then i can create containers it'll auto install python and whatever else i define ?

ionic raft
#

I've run collectstatic in the console and gotten the following:

#

I have 130 files but they're not showing on the site...hmmm

serene prawn
ionic raft
#

But even though the files are on the AWS object, they're not displaying

serene prawn
#

How does aws serve your static files from a container?

ionic raft
# serene prawn How does aws serve your static files from a container?
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3StaticStorage'
AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME')
AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
AWS_DEFAULT_ACL = 'public-read'
# AWS_DEFAULT_ACL = None
AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com'
AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400'}
AWS_LOCATION = os.environ.get('AWS_LOCATION')
AWS_S3_FILE_OVERWRITE = False
STATIC_ROOT = '/static/'  # Added for deployment```
#

Good grief...I really do NOT enjoy deployment

amber ember
#

it's like anything else, just something you're not familiar with

ionic raft
#

So....according to django documentation...

#

And yet.....that. dpes. not. work!

#

So, I try AWS...and that. does. not. work

serene prawn
#

Do you have your static files served on domain.com/static/?

#

Can you access any other files?

ionic raft
#

NONE

#

I am FOLLOWING the literal steps.

#

This is not ab out not being familiar. This is about following the steps and it not working

#

It is BS like this that drives me nuts

#

I have STATIC_ROOT = '/static/' and then run collectstatic...but nope

#

So, I know I have collectstatic in the docker image.

RUN python3 manage.py collectstatic -c --noinput \
    && chmod 777 $APP_HOME```
#

So, when the docker build runs it should collecstatic

#

According to Django documentation that. should. work.

#

What am I missing?

#

No css files for admin styles...no css files for front end

#

TF?

#

I know collectstatic ran because when I run it again, I get told as much:

#

So what am I missing?

#

130 static files got moved to /static on build. Yet, nada front end. Why?

#

According the Django documentation I have followed the steps.
This is not about familiarity...this is about following the steps and missing something

#

What am I missing>

#

live docker container shows static folder

#

I can see files there...interesting, can't see admin files...

#

But I can see the favicon and css files

#

So that looks correct. collectstatic did indeed do that

#

So, if I can see a static folder in the container and I have STATIC_ROOT set, why aren't they showing on the front end or in admin?

ionic raft
#

Do I need to expose nginx?

#

I can see EXPOSE 8000 but I am not clear on whether I'm actually exposing nginx. No styling files are coming across at all

plush wigeon
ionic raft
#

I'm digging deeper. The good news is, once I work this out, it will be done. It's the final step for deployment

ionic raft
#

I've taken this to #help-rice
I'm definitely stumped here

nimble berry
serene matrix
#

I don't know if this is the right place to ask but in django is it faster/cheaper on processor and memory to use a "for loop" to count/sum db entries or to use query aggregators?

Eg.
X = model.filter
S =0
For I in x: s+=l.amount

Vs

X =model.filter().aggregate(sum())

ionic raft
#

I'm absolutely stumped. Deployed django app in docker-container to Digital Ocean. Static files won't be served either through nginx or AWS. I've been sitting for sometime in #help-rice
IF anyone has experience with deploying Django in Digitial Ocean through docker I would really appreciate you taking a peek.

serene matrix
ionic raft
#

settings.py py STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static')

ionic raft
#

Remember, I'm deploying to production...so I need to declare STATIC_ROOT

#

But even though the files for admin have been collected into the static folder, admin renders like this....

#

That is a broken admin django page. The admin styling files simply aren't being served

#

When I inspect Network I see...

#

NONE of this makes any sense

austere cairn
#
import io
import os
import dns
import uuid, base64
from flask import request
from flask import Flask
from flask_sock import Sock

app = Flask(__name__)
sock = Sock(app)

@app.route('/')
def index():
  return "<html><body style='color:white;background-color:black;'>An dumb api</body></html>"

@app.route('/LOLZ')
def Upload():
  return "LOLZ"

@sock.route('/echo')
def echo(sock):
    while True:
        data = sock.receive()
        sock.send(data)

app.run(host="0.0.0.0", port=443)
``` y dis not work
serene matrix
ionic raft
#

What I am noticing is that the IDE is showing errors on the calls to those css files....now that I've switched to production settings

serene matrix
#

Oh I see

ionic raft
#

OK...I have found a problem I can't workaround...

#

To move to production I can't have STATIC_ROOT and STATICFILES_DIR py STATIC_ROOT = os.path.join(BASE_DIR, 'static') STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static'), ]

#

HOWEVER, removing STATICFILE_DIRS breaks the include static in the templates

serene matrix
#

I’m doing some reading and I’m seeing that you have to find a way to set the x-content-type-options in your deployment env.

ionic raft
#

This web app works perfectly in dev

#

It's ONLY when deploying that I have a problem

serene matrix
ionic raft
#

The answer on that thread isn't encouraging

#

The build log shows collectstatic deleting the css files!

[2022-04-24 02:54:02] INFO[0029] Running: [/bin/sh -c python3 manage.py collectstatic -c --noinput     && chmod 777 $APP_HOME] 
[2022-04-24 02:54:03] Deleting 'Whurthy/events-css.css'
[2022-04-24 02:54:03] Deleting 'Whurthy/favicon.ico'
[2022-04-24 02:54:03] Deleting 'Whurthy/main.css'```
#

Why is that happening???

serene matrix
#

I just read that the path provided in static_root can't be in staticfiles_dirs

ionic raft
#

Which I did. The end result is static files simply aren't being served by this hosting solution

#

This is so sad....I've got the site deployed...but simply won't serve the static files.

ionic raft
#

I've been banging my head against this all day. I need to step back.

ionic raft
#

However, I did get the site deployed today. So that's something

#

Hmmm....may have had some progress...the files are not being deleted now that I've namespaced them in a static folder within an app rather than the root directory

#

I suspect nginx config is the problem

#

This is an nginx issue. I need to configure nginx to correctly serve up static files

serene matrix
#

Oh alright thats a lead

ionic raft
#

It is. Now I just have to work out how to configure the default.conf file to correctly serve up static files on port 80

devout sparrow
#

Anyone with flask and SQL experience can help me debug, I'm building a movie booking system and it is 90% done but am having minor issue and I cant seem to find what's wrong #β˜•help-coffee

cerulean badge
#

(django) I think I have found a bug in drf. I have custom permission which when returns false the response should have

{
    "detail": "You do not have permission to perform this action."
}

which does happen but if the user is not authenticated the response has

{
    "detail": "Authentication credentials were not provided."
}

even if the reason for not permitting wasn't authentication

devout sparrow
#

Anyone with flask and SQL experience can help me debug, I'm building a movie booking system and it is 90% done but am having minor issue and I cant seem to find what's wrong #help-lemon

elder rover
#

hi, im create appointment, i am stuck at to create functions max limit per time . How to set max booking per time If I say I want to set every time an example at 8AM users can book max limit 10 times

#

from django import forms

from booking.models import BookingSettings

class BookingDateForm(ChangeInputsStyle):
date = forms.DateField(required=True)

class BookingTimeForm(ChangeInputsStyle):
time = forms.TimeField(widget=forms.HiddenInput())

class BookingCustomerForm(ChangeInputsStyle):
user_name = forms.CharField(max_length=250)
user_email = forms.EmailField()
user_mobile = forms.CharField(required=False, max_length=10)

class BookingSettingsForm(ChangeInputsStyle, forms.ModelForm):
start_time = forms.TimeField(widget=forms.TimeInput(format='%H:%M'))
end_time = forms.TimeField(widget=forms.TimeInput(format='%H:%M'))

def clean(self):
    if "end_time" in self.cleaned_data and "start_time" in self.cleaned_data:
        if self.cleaned_data["end_time"] <= self.cleaned_data["start_time"]:
            raise forms.ValidationError(
                "The end time must be later than start time."
            )
    return self.cleaned_data

class Meta:
    model = BookingSettings
    fields = "__all__"
    exclude = [
        # TODO: Add this fields to admin panel and fix the functions
        "max_booking_per_time",
        "max_booking_per_day",
    ]
stable bear
#

If you deploy a web app on a VPS like linode, how do you edit the code of the web app and deploy the new version? Which steps do you have to repeat?

nimble berry
serene prawn
#

Unless you run your app in container

stable bear
#

do you need to reload gunicorn?

serene prawn
#

Yep

stable bear
nimble berry
stable bear
#

if you close the putty/ssh would the server stop working?

nimble berry
stable bear
#

I am getting this error when using supervisor with gunicorn in deployment with linux ubuntu server

supervisor: couldn't chdir to /home/flask_app: ENOENT
supervisor: child process was not spawned
ionic raft
# elder rover from django import forms from booking.models import BookingSettings class Boo...

First observation - use ticks to format code...three of them for multiple lines...a single tick each side for a single line:

print('Look how readable this code is!')

Second observation - if you want to control input going with forms.py for the app, importing the model, and building a form with def clean(self): method you can do great validation.
You can also validate in view.py, but I find forms more logical, intuitive and understandable. You could do your validation upon form submission.

Third observation - you could also add logic to views.py to calculate the number of bookings (per your requirement) and adjust the template from there.

#

!format

lavish prismBOT
#

String Formatting Mini-Language
The String Formatting Language in Python is a powerful way to tailor the display of strings and other data structures. This string formatting mini language works for f-strings and .format().

Take a look at some of these examples!

>>> my_num = 2134234523
>>> print(f"{my_num:,}")
2,134,234,523

>>> my_smaller_num = -30.0532234
>>> print(f"{my_smaller_num:=09.2f}")
-00030.05

>>> my_str = "Center me!"
>>> print(f"{my_str:-^20}")
-----Center me!-----

>>> repr_str = "Spam \t Ham"
>>> print(f"{repr_str!r}")
'Spam \t Ham'

Full Specification & Resources
String Formatting Mini Language Specification
pyformat.info

ionic raft
# nimble berry no

Massive thanks again, bruh! Site deployment is such a relief, and also passing all testing so far too!

nimble berry
ionic raft
stable bear
ionic raft
stable bear
ionic raft
nimble berry
stable bear
#

this is what i get

nimble berry
stable bear
ionic raft
#

that's light on perms...some read but not comprehensive?

nimble berry
# stable bear

your error message said that supervisor was trying to chdir (or cd, change directory) into /home/flash_app
is there a supervisor configuration file that needs to be changed to have the right path maybe?

stable bear
#

i send the conf file

ionic raft
#

is -3 high enough perm level?

#

I am newish to Linux too...so pls don't listen to me πŸ˜‰

stable bear
#

this is my error message

ionic raft
#

When is supervisor being given perms?

stable bear
nimble berry
ionic raft
#

Flask...good times πŸ™‚

#

Funny how I spent a month with flask and then went to Django...because amazing πŸ™‚ But Flask was solid

nimble berry
ionic raft
#

I've been doing the Django-Tango with ORM...building apps with PostgreSQL. Not had much use for API work, except to do things like send texts and emails.

#

I LOVE Django's ORM. I'm really low on SQL skill ladder...but what I can do with ORM in Django...good times

#

The app we deployed is at https://whurthy.com by the way. In alpha testing, so not much write up about it...

#

Let's just say that Whurthy does things that we've not seen any other event mgmt solution do

#

Which reminds me...I should really write something up for non-authenticated users on the home page. But it's actually a B2B solution.

nimble berry
ionic raft
#

So if I were opening up an API, FastAPI looks to be a solid option?

#

That'll be needed for when we want to build some apps

nimble berry
ionic raft
#

But now...the Django-Tango is the dance I'm in

ionic raft
#

AND, it looks like with Digital Ocean I've the basis of rapid deployment. Although, I really do need to get that refined. Good for testing for now

#

The ORM in Django, really lots of fun to use. Very intuitive

nimble berry
ionic raft
#

So I wouldn't do ORM without an IDE

#

Not interested in wasting my time

#

Love me some search on the fly, not gonna lie πŸ˜‰

#

And contextual search...none of that unguided cross site searching either πŸ˜„

nimble berry
# ionic raft AND, it looks like with Digital Ocean I've the basis of rapid deployment. Althou...

you are deploying the static resources to aws s3, which is fine unless you want to avoid having aws as well for cost reasons or similar
if you would have wanted to serve the static files from your container where you run your django app you could have been running both gunicorn and nginx in the same container using systemd or supervisor or anything like that and change your entrypoint in your dockerfile accordingly, even if it's not best practice it can save money/cost of not having to use multiple containers or service providers

ionic raft
#

This is not a task I want to learn and apply for WHurthy. Want deep expertise, someone who knows what they're doing.

#

It's a B2B solution, where each business (client) will have their own DB/instance

#

that's going to mean a big need for CI/CD pipe, and some elegant architecture both from a scalability and operational POV

#

This app looks so sweet on my smartphone, I'm not so sure iOS/Android apps will be urgent

nimble berry
ionic raft
#

And no deep JS....so silly fast

ionic raft
#

The standout part for me...using htmx to render inline forms that are so easy to use. Really enjoying the UX on my phone for managing bookings

#

Django's built in inlineformfactory...gets the job done, but it's nasty

#

Htmx for inlineforms...the holy grail of repeating data input

brisk drum
#

Someone experienced with selenium? i need help with a thing

nimble berry
# stable bear

it's better if you put text in the chat as text instead of a screenshot

#

!code

lavish prismBOT
#

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

alpine flicker
#

hello everyone

split swift
#

in need help wuth some html

alpine flicker
#

i need some help in django webframwork

split swift
#
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>BuzzMoney</title>
    <style>
      .btn {
        height: 100px;
        width: 100px;
        position: relative;
        top: 350px;
        left: 710px;
        padding: 0;
        border: none;
        background: none;
      }
      .Balance_text {
        font-size: 150%;
      }
    </style>
  </head>
  <body>
    <button class="btn" onclick="button_pressed()">
      <img
        class="Image_of_btn"
        src="EARN MONEY.png"
        alt="EARN MONEY"
        height="100px"
        width="100px"
      />
    </button>
    <p class="Balance_Text" id="Balance"></p>
    <script type="text/javascript" src="index.js"></script>
  </body>
</html>
#

i am changing the font size

#

but still the font size isn't changing in the website

nimble berry
ionic raft
ionic raft
split swift
ionic raft
#

And getting stuck is where you really learn

split swift
#

i know

nimble berry
split swift
#

now i am not able to move the text

#

in .Balance_Text {
position: relative;
top: 100px;
}

#

it aint moving

ionic raft
#

So I finally sat down and wrote out what Whurthy does after 93 days of Django....

nimble berry
ionic raft
#

And I just remembered you can track seating by venues too.

#

Django is an AMAZING web dev framework....truly AMAZING

nimble berry
ionic raft
#

Already deploying those changes. Love me some automated pipeline from github to auto deploy

#

And done πŸ™‚

plush wigeon
#

hmm is docker only effective in deploying web apps?

nimble berry
plush wigeon
#

not desktop apps, because you can just package them and make an installer?

ionic raft
nimble berry
nimble berry
fickle basin
#

hello is there a way to call a JS function into a Django form ?

thorn igloo
ionic raft
#

Couple of observations. First, use formatting (link to follow) for code. Second, can you use those lovely backticks to post your settings.py for DB? EDIT: Oh, and I suspect models.py from the...users app (?)...may be in order.

#

!format

lavish prismBOT
#

String Formatting Mini-Language
The String Formatting Language in Python is a powerful way to tailor the display of strings and other data structures. This string formatting mini language works for f-strings and .format().

Take a look at some of these examples!

>>> my_num = 2134234523
>>> print(f"{my_num:,}")
2,134,234,523

>>> my_smaller_num = -30.0532234
>>> print(f"{my_smaller_num:=09.2f}")
-00030.05

>>> my_str = "Center me!"
>>> print(f"{my_str:-^20}")
-----Center me!-----

>>> repr_str = "Spam \t Ham"
>>> print(f"{repr_str!r}")
'Spam \t Ham'

Full Specification & Resources
String Formatting Mini Language Specification
pyformat.info

fickle basin
fickle basin
native tide
#

If I have a HTML <a> element that goes to mywebsite.com/hello and have a Flask route for "/hello" Flask will still pick it up right?

heady tusk
#

I'm trying to clone a repo but I am getting an error
[14:55]
can I get help?
[14:55]
jsoto-codes@jsoto:~/repos$ sudo git clone git@github.com:js-machinecode/github_test.git
Cloning into 'github_test'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
[14:56]
https://0paste.com/368642#hl

native tide
#

hi guys, i remember there was a tag/extension that can make the form more cute

#

hi guys, i remember there was a tag/extension that can make the forms look more cute

#

can you tell me which one it was ?

#

my code look ugly

#

ping me if you can help me

fickle basin
#

@native tide download crispy form then {{form |crispy}}

nimble berry
native tide
fickle basin
native tide
fickle basin
#

@native tide you can use the usercreationform provided by Django to do so !

#
def register(request):
    if request.method == 'POST':
        form = UsercreationForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            messages.success(request, account has been created! ')
            return redirect('your template name to login')
    else:
        form = UserCreationForm()
    return render(request, 'you template to registerl', {'form': form})```
#

Hope it helps you

native tide
native tide
small grove
#

in flask is there a way to have it not log favicon requests e.g.
2022-04-24 17:34:30,708 - [werkzeug | _internal.py:224] - INFO - 127.0.0.1 - - [24/Apr/2022 17:34:30] "GET /favicon.ico HTTP/1.1" 200 -
for every request

fickle basin
#

Throw you should use a Foreignkey rather than a OneToOne relationship

native tide
#

Let’s say I’m making a blog and a user searches for a blog title. So the server returns any blog who’s title resembles what the user searched. What I want are the blog titles to be displayed and the client can then click the blog titles to see the full blog on a new HTML page where the link is something like myblog.com/blogs/blogtitle is there any efficient way to do this? I was thinking Everytime a new blog is added a new HTML file is created but im not sure about how efficient that is.

brisk drum
#

i'm making a script with selenium but i couldn't find some element in a page, so i printed the html code of it and i get this:

#

but actually the html code of it is this:
does that mean that the page blocks bots?

nimble berry
fickle basin
nimble berry
brisk drum
nimble berry
brisk drum
#

it's the same link to the page i'm connected

opal vale
#

Hey, I'm looking for good fastapi project with implemented "everything" correctly
for exemplary structure of code etc. (with tests, database interactions, pydantic schemas etc.)

Does anyone by any chance have it? πŸ˜„

dim wolf
#

struggling with this problem for last few days... I have set up a MySql 8 db with django 4 and python 3.10; I want user to see their updated balance each time a new transaction is added via web form. Should you calculate their new balance at the db level, or within the django form, or in a separate python function?

dim wolf
# thorn igloo i'd say db

ok still trying to get my head round how to do this. i've been following the Learning SQL and SQL Cookbooks and files can't see a way to run a direct calculation between two or more fields

thorn igloo
#

what kinda calculation are we talking here?

dim wolf
thorn igloo
ionic raft
ionic raft
# dim wolf struggling with this problem for last few days... I have set up a MySql 8 db wit...

There are two main schools of thought. The bottom heavy school recommends striving for coding logic at the model level. Tracking a balance against a record makes sense.
I'm only a year into Django, and the DB I've been using has been PostgreSQL (so not much help on that regard). The app heavy school tends to build logic into views.py. That is infinitely better than putting logic in your template πŸ˜„
forms.py is great for declaring different flavours of form, and I make great use of validating input at that level.
Speaking truthfully, I plan on learning more about how to work more bottom heavy, but I'd likely approach this by putting logic in views.py and use ORM to write to DB. I could envision some methods at the model level for doing things like returning a balance (but that's a pure guess).
Good luck, bruh

plush wigeon
#

i'm using SQLite (library not cmd line), how do I delete a record based off of its name and not ID?

#

its a bill tracker app, and there are 2 columns.. bill_name and cost

ionic raft
#

Querying with Django?

plush wigeon
#

no its on tkinter

ionic raft
#

Hmmm...web dev might not be the ideal channel for tkinter. I did dabble with back in a boot camp. Had fun. Foggy memz though.

plush wigeon
#

ok ty

native tide
nimble berry
# plush wigeon ok ty

regardless if it's web or tkinter you might have some luck in #databases
otherwise, going without an ORM here (warning: untested code, just writing it from memory):

with conn:
    sql = 'DELETE FROM bills WHERE bill_name=?'
    cur = conn.cursor()
    cur.execute(sql, (bill_name,))
    conn.commit()
ionic raft
plush wigeon
timid sparrow
#

hello , i know basic python programming ..whenever i see utube for software engineer , i see them using java or something else shall i switch to java too? or is python also good for getting a job

pseudo pilot
split swift
#

anyone knows how i can make a second page for my website in html

#

for example

#

so how do i do that

nimble berry
nimble berry
subtle drum
#

Hi, I am trying to create a field with RadioField but it only allows 1 button selected. I want multiple selection, how do I do that?

nimble berry
frank shoal
#

It's been a while since I've done scss. Do I need the & when doing & a {}

worn crystal
#

Currently, I'm using session variables to pass some information between my flask app. Should I change this to something else that might be more secure? Or is this okay?

left parrot
#
<button>
  <div id="box">
  </div>
<i class="fa-solid fa-house-chimney-window" style="font-size:9.2em;"></i>
<h1 style="margin-top: -18px; font-size: 0.6em; color: gray;">Tobias LV</h1>
</button>

How would I go about making the window only yellow?

serene matrix
serene matrix
#

Or use an svg I guessπŸ€·πŸΎβ€β™‚οΈ

nimble berry
#

i think you have some problem with pip and how it's installed

deep glade
#

Anyone know any Odata Libs for python, seems like everything I am finding hasn't been updated in ages.

nimble berry
#

the internet says: python3 -m pip install --user --force-reinstall -U and that --user for the reinstall and upgrade is the important bit

ember narwhal
#

can someone help me with flask

#

I am trying to use some static files but i am code code 500 and some weird traceback

#

here is the code

dense slate
#

why is the traceback weird

dense yarrow
dim wolf
ionic raft
pseudo spire
#

https://nao.gg/

my icons are blurry but when you hover over them for a second they are fine, why?

wicked wraith
#

Unsure where else to put this -- I'm looking for some help with the YouTube API.

I want to create a playlist on a given channel, but I'm unsure how to do that. I've got an API key for the account the channel is associated with, but https://developers.google.com/youtube/v3/docs/playlists/insert#usage doesn't seem to explain to me how I can choose which channel associated with my account I can use.

Many thanks all.

hollow dragon
#

hey mates. I started learning Flask + Python a couple of weeks ago and I built an app with database, you can register, login and obviously logout. you have to register to see the content on the web app. I was wondering what could I make out of this. I was thinking about building a ToDo list in there but not sure...

#

I want to build a flask project for an internship

urban cape
#

Rate this: thinkmon

hollow dragon
rain rivet
#

I'm trying to scrape edabit.com's python challenges to make a script for automating my process, but none of the actual content is in the source code for the website. Any workaround for this? Here's an example challenge https://edabit.com/challenge/JzBLDzrcGCzDjkk5n
Edit for clarity: I want to scrape the description, notes and examples etc

astral pagoda
#

@brave tulip did you add the html to the page like this https://www.w3schools.com/tags/tag_doctype.asp ?

scenic oak
#

is beautiful soup considered a automated testing tool like selenium?

outer apex
nimble berry
frank shoal
#

I think bs4 is best for parsing out the <meta> tags of html

#

i.e. when you post a link in discord, the discord backend calls that url and finds meta tags to populate the embed

plush wigeon
#

beauitful soup parses html, so its good for web scraping (gathering data from websites). if you want to sift through html to grab certain data from certain websites, you can do that

#

i feel like you can make a script that can auto-buy items when they're in stock

#

with selenium + bs4

tiny ermine
#

hey guys, im making a website application thing that features a sorting visualiser

#

the backend is gonna be coded in python - the coded algorithms and related helper code

#

and the visualisation is gonna be in js

frank shoal
#

are you looking for tips?

#

you could use chartjs on the frontend.

tiny ermine
#

im wondering how i can transfer data across the languages efficiently

frank shoal
#

using json?

tiny ermine
#

will that be quick?

frank shoal
#

What backend framework are you looking to use?

tiny ermine
#

probably django or flask

frank shoal
#

with flask, you can return jsonify(data) to return a json response

tiny ermine
#

yeah but how will i make thatt connection so the two languages can interact with each other

#

will it be like a server or database?

frank shoal
#

from javascript, you would make a rest request using fetch() to get the data.

tiny ermine
#

and python would do a POST?

#
def get_variables():
    return inspect.currentframe().f_back.f_locals

def is_deepest_loop(node):
    return not any(
        child != node and isinstance(child, (ast.While, ast.For))
        for child in ast.walk(node)
    )

class FunctionTransformer(ast.NodeTransformer):
    def visit_For(self, node):
        self.generic_visit(node)
        if is_deepest_loop(node):
            return ast.For(
                target=node.target, 
                iter=node.iter, 
                # body=[ast.Expr(value=ast.Yield()), *node.body],
                body=[ast.Expr(value=ast.parse("yield get_variables()")), *node.body],
                orelse=node.orelse
            )
        return node

    def visit_While(self, node):
        self.generic_visit(node)
        if is_deepest_loop(node):
            return ast.While(
                test=node.test,
                body=[ast.Expr(value=ast.parse("yield get_variables()")), *node.body],
                orelse=node.orelse
            )
        return node

def bbsort(array: list):
    index_length = len(array) - 1
    swap_counter = -1
    while swap_counter != 0:
        swap_counter = 0
        for i in range(index_length):
            if array[i] > array[i+1]:
                array[i], array[i+1] = array[i+1], array[i]
                swap_counter += 1
        index_length -= 1
#

because right now, i have made itt possible for you to input your own sorting algorihtm

#

and it would get converted into a generator that returns the "debug" data every time u do next(bbsortInstance)

#

and that debug data would get sent to the JS

frank shoal
#

quick example. ```py
app = Flask(name)

@app.get("/getData")
def get_data():
return jsonify(hello="world")

```html
<html>
<body>
  <p id="data"></p>
  <script>
    fetch("/getData")
      .then(data => data.json())
      .then(data => {
        document.getElementById("data").innerText = JSON.stringify(data);
      });
  </script>
</body>
</html>
tiny ermine
#

is there any documentation/websites i can read up on this because i don't want to keep pestering you

frank shoal
#

I suggest the mdn (mozilla developer network). It has great community documentation.

tiny ermine
#

thanks!

worn crystal
#

Does anyone have suggestions on how to implement full text search in flask?

split swift
#

can someone who knows html well dm me

#

i have a doubt

open sierra
#

i am websraping python gpu information and i am h aving trouble getting the user rating

#

this is the line i want to pull

<i class="rating rating-4-5" aria-label="rated 4.6 out of 5"></i>

and this is how i am trying to pull it

ratingElementFourStar = containerElement.find("i", class_="rating.rating-4-5")

but it outputs

None

any ideas?

#

this is my whole file:

#https://realpython.com/beautiful-soup-web-scraper-python/ < tutorial
from bs4 import BeautifulSoup
import requests

page = requests.get("https://www.newegg.com/p/pl?d=rtx&N=4131%204841%204814%204021%204020%204019%204018%204017")
soup = BeautifulSoup(page.content, "html.parser")
results = soup.find(class_="list-wrap")
container = results.find_all("div", class_="item-container")

for containerElement in container:
    priceElement = containerElement.find("li", class_="price-current")
    nameElement = containerElement.find("a", class_="item-title")
    ratingElementFiveStar = containerElement.find("i", class_="rating.rating-5")
    ratingElementFourStar = containerElement.find("i", class_="rating.rating-4-5")
    print(priceElement)
    print(nameElement)
    print(ratingElementFiveStar)
    print(ratingElementFourStar)
    print()
#

neither of the ratings work, they both print python None

split swift
#

dm me

hidden marten
#

@open sierra on mobile so I haven't checked, but I'm guessing the data is not sent with the HTML. it's probably loaded from some JSON via fetch/XHR

open sierra
hidden marten
#

assuming I'm right, request the same JSON

open sierra
#

How would I go about that

#

I do not know how to request JSON

#

And how did you know it’s JSON?

hidden marten
#

I'm just guessing. use your browser's devtools' network tab to check

indigo kettle
#

you may have to do something like
containerElement.select(".rating.rating-4-5")

open sierra
#

Or class

#

I’m new to html and python and web scraping

indigo kettle
#

this is more library specific knowledge than python. I'd have to check the docs or just try it

#

it looks like it returns a list

open sierra
#

What

#

I’m confused

tribal frigate
#

can anyone help me with eval()

#

?

indigo kettle
# open sierra I’m confused

confused about?
this works for me

import requests
from bs4 import BeautifulSoup

response = requests.get('https://www.newegg.com/p/pl?d=rtx&N=4131%204841%204814%204021%204020%204019%204018%204017')

soup = BeautifulSoup(response.content, features='lxml')

four_of_five = soup.select('.rating.rating-4-5')
print(four_of_five)
#
[<i class="rating rating-4-5"></i>, <i aria-label="rated 4.6 out of 5" class="rating rating-4-5"></i>, <i aria-label="rated 4.7 out of 5" class="rating rating-4-5"></i>, <i aria-label="rated 4.7 out of 5" class="rating rating-4-5"></i>, <i aria-label="rated 4.6 out of 5" class="rating rating-4-5"></i>, <i aria-label="rated 4.7 out of 5" class="rating rating-4-5"></i>, <i aria-label="rated 4.6 out of 5" class="rating rating-4-5"></i>, <i aria-label="rated 4.6 out of 5" class="rating rating-4-5"></i>, <i aria-label="rated 4.4 out of 5" class="rating rating-4-5"></i>, <i aria-label="rated 4.6 out of 5" class="rating rating-4-5"></i>]
nimble berry
# tribal frigate can anyone help me with eval()

you should really avoid eval() and only use it as a very last resource (many times one can redesign ones solution to not need it) and be ware of possible security risks associated with using it

tribal frigate
#

ah yes im aware of it, but my school needs me to exploit it on a website

#

but @nimble berry there are restrictions in it

rain rivet
#

@outer apex right, i see, thanks.

hollow dragon
#

If an internship expects me to build a flask project, what would you recommend?

#

I finished Miguel's book

#

Know the foundations

#

Also have experience with html, css, JavaScript

#

But just started learning Python a couple weeks ago

nimble berry
nimble berry
tribal frigate
nimble berry
tribal frigate
#

its a capture the flag

nimble berry
tribal frigate
#

we are given a website and we are told that a website uses eval in its python code

nimble berry
nimble berry
tribal frigate
#

ok thank you rndpkt

split swift
#

how do i make so that it doesn't create any space

bold void
#

hi can any one help i am having error in django

#

yaa

#

ok

#

thanks its get working now

brave tulip
#

any way to check what the user is currently typing in to a html form (before enter/ submission)

inland oak
#

although describe what u wish to achieve, perhaps u ask the wrong question and receive answers for a wrong question.

brave tulip
#

i want it to autocheck the input after each letter and make it submit if a condition is true

#

i'm currently using flask

open sierra
formal rapids
formal rapids
brave tulip
#

oh, it's python, you gotta use underscore

formal rapids
#

Oh

#

I sent computers from my flask app to my html

brave tulip
#

show your python code

formal rapids
#

Ok, just a moment

brave tulip
#

ah

formal rapids
#

I have to change "computer name" to underscore instead of space?

brave tulip
#

the your variables are ```html
...
<td>{{ computer["User"] }} </td>
<td>{{ computer["Computer name"] }} </td>
<td>{{ computer["Computer Brand"] }} </td>
...

formal rapids
#

Ok

brave tulip
formal rapids
#

Dot

#

Ok

brave tulip
#

it's a dictionary {"key":"value"}

formal rapids
#

Because i tried eith computer.["user"] and it didnt work

#

Ok

#

Alright thanks

brave tulip
formal rapids
#

Ok

brave tulip
#

how u can access key data: @formal rapids

myDict = {"key":"value"}
print(myDict["key"]) #OUTPUT: value
brave tulip
formal rapids
#

Ok

formal rapids
#

So it'll get value for each row

brave tulip
#

nevermind then

formal rapids
#

If there was no space i could access it like computer.User

#

Without the brackets but with spaces it failed

#

Spaces i meant

brave tulip
#

use the brackets

inland oak
# brave tulip i want it to autocheck the input after each letter and make it submit if a condi...
#

people do it in elegant way in Javascript Frontend Frameworks though

#

they have mvvm data binding model things which makes stuff like that easy without any hacks

scenic dove
#

Hello

#

so in css the background-color is the color of both content and padding boxes right?

tiny snow
#

I think so

random beacon
#

for easy , quick websites that are secure, would django or flask be the better option?

#

keeping mainly security in mind.

novel patio
#

is anyone else having problems with visual studio code

brave tulip
#

I'll probably migrate to js

inland oak
#

you need to use Vanilla JS, JQuery or linking statically Vue.js for example, or just making frontend in the frontend framework: React / Vue.JS / Angular

#

building frontend in frontend frameworks is the best option. All the previous options are substitutions, than worse than closer to the beginning

brave tulip
#

I'll check that out!

#

thanks a lot!

high hill
#

mr sirs, i am facing an error in django when trying to go GET requests

#

i will now post error log in text file

lavish prismBOT
#

Hey @high hill!

You either uploaded a .txt file or entered a message that was too long. Please use our paste bin instead.

high hill
wraith valley
#

oh wow

dim rover
#

wow thanks for posting the FULL traceback

wraith valley
#

Looks like your connection timed out

high hill
#

sorry im dumb idk how i should post errors T_T

#

yea so what is happening is, this error comes around randomly

dim rover
#

is it polling or alerts or smth

wraith valley
#

No no, we're thanking you

high hill
#

im doing GET requests to a separate deployment, lets say every 10 secs (total number of GET requests are 15) and randomly this will happen

high hill
wraith valley
#

People never post full tracebacks and it's shit hard to know what actually went wrong

high hill
#

oh also, i thought this was because of djangos inbuild WSGI so i used gunicorn, still same error ;-;

wraith valley
high hill
#

hmm, so this shouldnt be an of django right ???

dim rover
#

does it happen if you increase the period between requests

wraith valley
#

Try to ping it every 30 seconds

#

Just for debugging

high hill
#

hmm, I am testing it right now, in the end i will keep the interval at 5-10 mins

#

icic, ill try 30

dim rover
#

you could even randomly wait a little extra

#

not sure that would help tho

high hill
#

though you know, sometimes it happens even when it has run 0,1 or 2 times too

wraith valley
dim rover
wraith valley
#

so it goes something like

20 | 20 | 20 | ERR | 30 | 30 | 30 | 30 | 20 | 20 | 20 | ERR
high hill
#

no issues, forget about it

wraith valley
dim rover
#

yea i dont know of specifics either

wraith valley
#

works well if you know the pattern

high hill
#

hmm, i guess i could do this if it persists when im testing it on cloud

wraith valley
#

try it out

high hill
#

but right now on local when i do this, the port-forward just closes, so i have to do that again manually

wraith valley
#

aah

high hill
#

yaah D:

wraith valley
#

do you controll the external server?

high hill
#

super

wraith valley
#

maybe startoff by making a resstart system

#

if that's an important endpoint it'll be a pain to have it go down randomly

high hill
#

πŸ‘€

wraith valley
#

with their VPS sure iirc

#

hm

#

sure

high hill
#

he vanished

brave tulip
#

@inland oak figured it out using your tips!

#

thanks!

hollow dragon
#

Yo guys, can i pm someone, whos experienced in Flask?

#

Anyone?

gusty hedge
#

just ask the question

hollow dragon
#

Alright

#

I built an app with database, with the help of Miguel's book, you can register, login and obviously logout. you have to register to see the content on the web app. I was wondering what could I make out of this. I was thinking about building a ToDo list in there but not sure...maybe doing something with API? I want to make a web app / page to have a project for an internship.

#

Do you have any idea?

brave tulip
#

make a up/ down vote website

gusty hedge
# hollow dragon I built an app with database, with the help of Miguel's book, you can register, ...

you can do either server side rendering (which is an old approach but brought back to life because some react frameworks) or build an API and consume it from frontend. Which one is the best is up to you and depends on context. Usually you want to build an API when you are building something that needs to be consumed by different clients (mobile apps, web interfaces, desktop application, other APIs, etc)

hollow dragon
#

Hmm

#

I have experience and projects with JavaScript and html and css, I switched to python and flask because an internship wants me to. I like it so far. Do you guys think its bad if I use help from stackoverflow or books?

#

Thanks for the help tho!

#

Appreciate it

gusty hedge
#

any help is good even more if it comes for free πŸ˜„

hollow dragon
#

πŸ‘ shipit

indigo kettle
indigo kettle
#

also, I'm familiar with css selectors so using this method is easier

hollow dragon
open sierra
#

What doc are you talking about btw

indigo kettle
open sierra
#

Oh cool thanks

native tide
#

Is there even a thing called as package in python?

#

My heroku just dont wanna read it

open sierra
#

@indigo kettle it still doesn't work. it outputs ```python
[]

this is my .py file:
```python
#https://realpython.com/beautiful-soup-web-scraper-python/ < tutorial
from bs4 import BeautifulSoup
import requests

page = requests.get("https://www.newegg.com/p/pl?d=rtx&N=4131%204841%204814%204021%204020%204019%204018%204017")
soup = BeautifulSoup(page.content, "html.parser")
results = soup.find(class_="list-wrap")
container = results.find_all("div", class_="item-container")

for containerElement in container:
    priceElement = containerElement.find("li", class_="price-current")
    nameElement = containerElement.find("a", class_="item-title")
    ratingElementFiveStar = containerElement.select(".rating.rating-5")
    ratingElementFourStar = containerElement.select(".rating.rating-4-5")
    print(priceElement)
    print(nameElement)
    print("rating is next")
    print(ratingElementFiveStar)
    print(ratingElementFourStar)
    print()

when i run this it outputs:

<li class="price-current"><span class="price-current-label"></span>$<strong>498</strong><sup>.98</sup> <span class="price-current-range"><abbr title="to">–</abbr></span></li>
<a class="item-title" href="https://www.newegg.com/Product/ComboDealDetails?ItemList=Combo.4491308" title="View Details">ASUS Dual GeForce RTX 3050 
8GB GDDR6 PCI Express 4.0 Video Card DUAL-RTX3050-O8G and ASUS TUF GAMING B450M-PRO S AM4 AMD B450 SATA 6Gb/s USB 3.0 HDMI Micro ATX AMD Motherboard</a>
rating is next
[]
[]

it outputs more than just this but for each item it looks like this
anyone else have an idea? im trying to grab an item rating from newegg using this line of html code: ```html
<i class="rating rating-4-5" aria-label="rated 4.6 out of 5"></i>

golden walrus
#

In Django, say I had two models:

class a(models.Model):
    x = models.BooleanField()

class b(models.Model):
    y = models.BooleanField()

Is there a way to only let y be True if x is also True?

#

hmm, it looks like maybe I need to look into making a custom save method

golden walrus
#

No, an object of class a would exist first. I'm trying to prevent an object of class b's y attribute from being initialized or updated as/to True if object a's x attribute isn't.

#

I guess if I'm concerned about that condition upon object of class b's creation, then I need to have a custom manager πŸ€”

upper ravine
dense slate
#

If someone has some good CSS skills, I have one main problem I just can't seem to crack. Hope I can share this link to share the issue? On mobile , https://OneHEP.com/build, my page is dealing with the issue where the VH is affected by the input bar at the top. It loads fine but then if you scroll down far enough to the bottom and then try to keep scrolling, the entire page slides up equal to the input bar height.

I've already replaced 100vh with 100% in a number of places after reading how it affects mobile viewports but cannot get this to go away. Anyone have insight into what aspect is still causing the bug?

lavish prismBOT
#

:incoming_envelope: :ok_hand: applied mute to @inland oak until <t:1651005515:f> (9 minutes and 59 seconds) (reason: newlines rule: sent 132 newlines in 10s).

calm plume
#

!unmute 370435997974134785

lavish prismBOT
#

:incoming_envelope: :ok_hand: pardoned infraction mute for @inland oak.

calm plume
#

you can make it css-highlighted by changing the extension on the link to .css?noredirect

inland oak
inland oak
#

here is example of reset file that should be applied in the absolute beginning of all your code
Plus it will make the code more cross browser supporting πŸ˜‰

dense slate
#

Ok will take a look, thanks!

#

You mean like flex-grow, etc?

inland oak
# dense slate You mean like flex-grow, etc?

I mean... that every element's size is combination of its own size + border + padding + margins. And due to different rules for each element in each browser
The size of every type of element is calculated differently.

That's why your 100% vh of some outter object is not really 100% in the end.
With reseting all elements to calculate their size with including border / padding (not remembering about marging)
the size of 100% or 100vh will be really 100% of the thing, and elements taking % or px of that size, will be taking precisely that size.

It will simplify for sure distribution of objects inside of another object.

#

Simple example which breaks the stuff when you aren't having reset:
You have a rectangle with 100% size
And you wish to have two smaller rectangles, taking exactly each taking 50% of space inside of the external one
If you don't have reset (and not having box-sizing: border-box.
The smaller objects will take size 100% + border + margin + whatever size, which will break all the... positioning.
With reseting and border-box, they will take exactly 50% size and filling precisely the external object

#

and yeah, it affects obviously flex elements too

dense slate
#

Hmm, alright thanks for the insight, I'll take a look at that.

#

I assumed that resizing is performed dynamically and so that wouldn't matter.

#

Because as you change the window, 100% is a different size and elements usually do change accordingly.

inland oak
#

Welp. Nope. When you set 100% size of the element, you set probably 100% of its internal size. But it adds border / padding / margins sizes, and woala. You have greater than 100% element.
With border-box, it should not be an issue. 100% will become real 100%

dense slate
open sierra
#

so i am trying to webscrape this webpage: ```html
https://www.newegg.com/p/pl?d=rtx&N=4131 4841 4814 4021 4020 4019 4018 4017

this is my .py file:
```python
#https://realpython.com/beautiful-soup-web-scraper-python/ < tutorial
from bs4 import BeautifulSoup
import requests

page = requests.get("https://www.newegg.com/p/pl?d=rtx&N=4131%204841%204814%204021%204020%204019%204018%204017")
soup = BeautifulSoup(page.content, "html.parser")
results = soup.find(class_="list-wrap")
container = results.find_all("div", class_="item-container")

for containerElement in container:
    brandingElement = containerElement.find("div", class_="item-branding")
    titleElement=containerElement.find("a", class_="item-title")
    rating = brandingElement.find("i", {"class":"rating"})["aria-label"]
    priceElement = containerElement.find("li", class_="price-current")
    #print(brandingElement)
    print(rating)
    print(titleElement.contents)
    print(priceElement.text)
    print()

i am trying to scrape this line:

<i class="rating rating-5" aria-label="rated 4.8 out of 5"></i>

i want to get the html rated 4.8 out of 5
and sometimes it outputs it, but for other items it outputs:

Webscraper Project\webscraper.py", line 13, in <module>
    rating = brandingElement.find("i", {"class":"rating"})["aria-label"]
TypeError: 'NoneType' object is not subscriptable

and obviously when it gets to this point it stops the loop, but for some items it works perfectly fine

upper ravine
#

Can you find only rating-5

worn crystal
#

anyone know if these errors are okay? I'm making a simple webpage with a iframe to a youtube video

grizzled prawn
#

Heya I wanted help

#

Can anyone help me?

#

I did this

#

i get this error

#

i have installed werkzueg

#

@gray lance could you help me?

devout sparrow
#

Hi

#

Anyone familiar with html

grizzled prawn
open sierra
pallid lily
#

This is a django question, Is there a way to execute a single action at the first migration attempt such as create certain objects in a model?

covert crystal
#

Hello people, can someone recommend an introduction to RESTful API (book)? Would be nice if it was based on python

gusty sky
#

Hello guys, any idea how to connect Vue frontend with FastAPI backend ?

thorn igloo
gusty sky
#

yes. I use fastapi + uvicorn +pymongo and it provides api and communicates with mongodb docker container.

#

But idk What should i do with VueJs in order to make a communication beetween FE and BE. I have heard that there are more solutions, idk which is the best

#

Probably using nginx ?

gusty sky
#

frontend and backend

thorn igloo
#

i'd recommend using the axios library to interact with the backend

#

you can use fetch too which is basically a default js library but axios has more features

gusty sky
#

thank you very much friend

random beacon
#

can django render ejs files ?

formal rapids
#

<td class="hide">{{ computer["History"] }}</td>

.hide { 
  display: none; 
}

.show:hover~.hide {
  display: block;
}```
can someone tell me why this works, using 'sibling'. but if i use space it doesnt?
#

<td class="hide">{{ computer["History"] }}</td>

.hide { 
  display: none; 
}

.show:hover .hide {
  display: block;
}```
this doesnt work
formal rapids
#

yes, but im talking about hovering over the show, it should display the hide

#

just the css

ocean slate
formal rapids
#

if i use the class name:
.show:hover .hide { display: block; }

it wont work

#

why is that?

#

i have to use
.show:hover~.hide

ocean slate
#

sorry I am beginner in css oew

#

now*

formal rapids
#

oh

ocean slate
#

may be use comma because they are two different class and no parent child case is there

split swift
#

Yoo

#

Anyone active

open sierra
#
for containerElement in container:
    brandingElement = containerElement.find("div", class_="item-branding")
    titleElement=containerElement.find("a", class_="item-title")
    rating = brandingElement.find("i", {"class":"rating"})["aria-label"]
    priceElement = containerElement.find("li", class_="price-current")

so this for loop checks for prices, ratings, and the name of an item on a website. it works. however, some items have no reviews, in which case it fails. how do i fix this? i was thinking of an if statement to check if the containerElement (the actual container the item and all its information is in) has a rating, but im not exacatly sure how to do that

outer apex
ruby sorrel
#

hello everyone πŸ™‚ noob here,
i dont know how to go about this in css

#

i put an overflow-x: scroll; for that container in the red dashed box but i kinda want to hide it under the my main container

open sierra
#

i did t his

#
if ratingElement != None:
        rating = brandingElement.find("i", {"class":"rating"})["aria-label"]
        print(rating)
#

and made a new element saying:

#
ratingElement = containerElement.find("i", class_="rating")
merry merlin
#

How is it looking guys?πŸ˜…

#

First time hand on Front-end

hollow dragon
#

i finally was able to migrate the db from my todo app to my web app (flask)..now I have a web app where you need to register and the login to see the content and then you can use your to-do list to add todos, update them or delete them...my plan is to add some new features to it, such as email integration, etc.

frosty aurora
#

I'm trying to build a simple web service that does auth through a magic link over email

Let's say the user types their email in and I send them a login link with some auth token

How can I securely tie that token with the browser? Cookies?

hidden marten
#

you don't have access to the cookies in the user's inbox. you have to store the token in your DB

frosty aurora
#

okay, so when they make a request to perform a privileged action, how should they pass the token back to me?

#

as a query parameter in the request?

hidden marten
#

oh. deeeeeeeefinitely not as query params
after they click the email, you set something in the session, generally as a cookie which keys into the database, but honestly just do whatever your web framework prefers
(usually, the auth token is only valid once; the session key persists in the browser's cookie jar)

frosty aurora
#

context: I'm trying to do really basic web app with a FastAPI backend where I can do auth strictly through email magic links to avoid the security risks that comes with storing passwords

#

there's no private info, no data collcetion, nothing to keep secret, so if I have to introduce passwords then the passwords themselves will be the biggest security headache

hidden marten
#

fastAPI is not really meant for webapps. looking at the docs, it doesn't have any built-in support for sessions. so you either need to invent sessions from scratch or switch to something like flask

#

I mean, I guess you can use fastAPI's openAPI support via api keys and then use fetch with credentials in your webapp................

#

but you'd still need to either accept that the token you mailed out is valid forever or turn the token in an api key for every browser session

frosty aurora
#

eh, I might be able to cook something up that's simple.

hidden marten
#

flask is pretty simple. you're making things complicated by using a screwdriver to hammer nails

frosty aurora
#

very true

#

I started with what I knew, and quickly stumbed into an edge case for something I don't

#

wouldn't be the end of the world to pivot

#

but also I've learned a lot about how all of this stuff works in the process

hidden marten
#

yeah, the webdev stack is really tall (and rickety)

frosty aurora
#

I'm sure there are a lot of people who would shudder at the top, but as someone who does low-level stuff + backend work most of the time, it's kinda crazy how far I can get with just FastAPI + loading HTML + CSS + JS as string.Template objects and returning them

hidden marten
#

this... is what flask is for

frosty aurora
#

fair

hidden marten
#
  1. if you're heavily invested in fastAPI (you're using api doc generation 'n stuff) and you want a static site that XHR's to your API, you can definitely get away with cobbling together something on top of fastAPI
  2. you can have both a flask app and an API running
  3. you can port your code to flask (which I don't think is very much work)
frosty aurora
#

Should I just port to Flask? yes

Will I probably cobble together my own Session mgmt for the memes? Also yes. Flask docs say it's basically just a dict where you track edit time.

Thanks for the advice though.

hidden marten
#

@frosty aurora nooooooooooooooooo. it appears to the developer as a dict, but under the hood it's

  1. a thread-local so it knows which request (and cookies and user) it's for
  2. writing the session data either directly to a cookie or to the db keyed by the cookie
#

there's a lot to consider wrt sessions:
how do you make them tamper-proof?
can you load session data from another webserver (so your webservers are stateless and, therefore, horizontally scalable)?

nimble berry
#

i would disagree, there are lots of advanced people even in this channel that use fastapi for web apps as far as i have seen and also big companies

frosty aurora
#

I mean so here's the workflow:

  1. generate and send an auth email
  2. user clicks email, I give them a session cookie, I keep a copy of that cookie for that user
  3. On my sqlite DB: INSERT INTO userauth VALUES (:username, :session, :last_access, :expiry)
  4. if the user is close to having a session expire, I do refresh and send a Set-Cookie on their next request

Yeah a sqlite DB isn't "horizontally scalable" but if this project consumes more than the meager GCP VM that I can afford then I should find a way to make enough money to solve it later

#

on my load tests right now I can serve like 20k+ concurrent users on a GCP e2-micro and pump out hundreds of thousands of request a second

#

If I actually need to serve millions of requests per second and figure out how to handle state across multiple machines, then I'll solve then problem when it's, you know, a problem

hidden marten
#

but how do you map usernames to fastAPI tokens?
unrelatedly, how do you make sure your session identifiers can't be guessed?

frosty aurora
#

make sure Session IDs can't be guessed?
Flask docs say to use secrets from the stdlib, I'll probably just do that
how do you map usernames to fastAPI tokens?
My token will probably just be some secrets.token_bytes encoded in base64, and my mapping from username to token is literally in the above query

#

SQLite handles inter-thread / process atomicity for me

#

So, at least for my very limited use case, seems like it'll be like 10-20 lines of Python given that the dependencies are doing most of the hard work for me

#

Anyways, if anyone does wanna roast my approach, I do very much appreciate the questions @hidden marten as it's very helpful

novel patio
#

a wesbite for a business where it tells you a little about the business and the days that there open and there contact information does that count as a business landing page

frosty aurora
#

I mean yes, but a "landing page" gets its name from being the first place that the user "lands" when they're visiting a website

#

you could have the πŸ’© emoji in 200 pt font as your entire website and if it's the first place I land when i type "http://your-business.com" then that's the landing page

hidden marten
#

@frosty aurora feel like a lot of details are being glossed over here. would be interested to see your implementation once you write it

frosty aurora
#

I was hoping to come to this channel to find out what details I'm missing. I'm happy to share my solution when I get around to rolling it out

#

I'll probably publish the whole codebase under Apache eventually

river vector
#

Could someone help me with something like a chat for me and my feiends in school

#

a simple chat website

hidden marten
#

@frosty aurora ok, details:
are the emailed tokens API keys or keys you redeem for something? (and is that something a logged in session or an API token?)
how do you expire emailed keys?
how do you expire sessions?

frosty aurora
#

for session keys

#

I could probably just do the same for emailed links

#

I expire them by doing a pass over the table like once a minute or something

#

If the DB really gets to be a hassle to deal with, I could just spin up a memcached instance

#

actually... I might just do that

hidden marten
#

when you say "emailing them a link", what's the link? how do you associate the link with a user?

sure, timeouts are in the DB, but how are you expiring them? do you have a thread running in your app? do you have a cronjob running separately?

#

not sure what memcached is doing for you. normally you use it to make things faster by caching stuff. what are you caching? you wouldn't want a server restart to log your users out

frosty aurora
#

I am caching sessions

#

I suppose a server restart logging everyone out isn't the most convenient

#

if I go the SQLite route, then either of those approaches is fine, but I'd probably lean towards just doing it in a thread

#

well, to be specific, I'd just spawn an async connection the aiosqlite and check on it

#

but a cron job could also do the trick

#

This project has too little functionality to be getting rebooted constantly

#

so the idea of people getting logged out isn't huge

hidden marten
#

servers reboot to take kernel upgrades, when the power goes out, etc.

frosty aurora
#

fair enough, sqlite it is

hidden marten
frosty aurora
#

let me just write the code snippet rq lol

silver sphinx
#

Has anyone here created a interactive webapp for their machine learning model? I trying to do that but unsure where to start.

nimble berry
hidden marten
#

I was considering signed, unencrypted keys

trim condor
#

Is anyone awake that's familiar with Filezilla and Notepad++?

frosty aurora
# hidden marten so what are you emailing users?
def generate_login_url(username: s):
  sendtime = datetime.utcnow()..strftime('%Y-%m-%dT%H:%M:%S.%f%z')
  utf8_token = username+sendtime
  hashed_token = hashlib.new('sha256', utf8_token).digest()
  b64_token = base64.url_b64encode(hashed_token).encode('utf-8')
  return f"mywebsite.com/login/?token={b64_token}"
nimble berry
hidden marten
#

(the 3rd line is a str, which is unicode, not utf8)
and then you're gonna store this hashed token in the DB?

frosty aurora
#

I can store the unencoded sendtime in the DB and then regen the hash

#

or store the token

#

same thing

nimble berry
#

yeah, encoding creation time instead of expiration time is probably better

#

jwt:s are generally not great if you have to be able to invalidate specific sessions at any time without advanced notice, but for this I think you would be a good fit

frosty aurora
#

the goal here is to have dead-simple, easy to debug login auth for a simple toy "social media project" that doesn't store PII and very very much isn't supposed to be used for anything important.

There are literally two features that require privileges

#

and they both have to do with uploading content, which 90% of a userbase never does

nimble berry
#

speaking of jwt:s and other things that are cryptographicly signed... i wonder how many enterprise, financial and government sites and systems that are vulnerable to generating ones own skeleton key due to CVE-2022-21449 😟

unkempt temple
#

lots of sites are super vulnerable to lots of them

#

plenty of sites are still running on windows server 2003

serene prawn
nimble berry
serene prawn
#

You might have one central gateway that proxies requests to all other services and handles things like authentication

nimble berry
serene prawn
nimble berry
#

we can't invalidate them instantly, but for our purposes one minute life latency in logging out a user is acceptable

#

i think others do it like that too

serene prawn
#

You use RS or HS?

nimble berry
serene prawn
#

Using asymmetric algorithm for JWT's won't really have any cons?

#

Otherwise you need to share your secret across all services

hard whale
#

Ayo!

#

Doctor!

#

Nice to see you here πŸ™‚

#

Can you take a look at my lollipop?

#

My lollipop needs some Doctor attention

native tide
#

Hi, I'm trying to figure out how to connect an app with IIS. Do I setup a web.config file to attack the scripts to?

hard whale
#

Please

#

It's ez but I'm stuck

nimble berry
serene prawn
#

Do you split your jwt issuing/auth service and users service?

#

That stores actual user information

serene prawn
#

Just asking, a friend of mine said he would rather merge them, imo they have different responsibilities

nimble berry
#

and what i was referring to before is that RSA and ECC has there own pros and cons
mostly to ECC:s advantage... unless lately if one has been running java for any service that validate the jwt πŸ˜†
the only other "advantage" i can think of with [the dinosaur] RSA over ECC is maybe that it's battle tested for an extensive time

#

so, just a mix up on my side between HS and ES for a short while, don't think i have ever used HS, not even for a PoC or toy project

nimble berry
serene prawn
#

You don't want private information like password hashes to leave users service, so you'd probably need to create separate endpoint for that? Or would you create a separate service? (That seems to be a bit too much)

nimble berry
nimble berry
serene prawn
#

And to not share password hashes across services

#

Right? πŸ€”

hard whale
#

@serene prawn You're not retrieving actual objects from your db - could you share some more info?