#web-development

2 messages · Page 59 of 1

rustic pebble
#

Java applets

zealous siren
#

but at my company, we have a ton of APIs and web pages powered by Java backends

#

applets, what year is it?

quick cargo
#

One of our sites runs off Clojure

#

😫

zealous siren
#

🤮

#

my company LOVES Java

#

in fact, one small group in my division writes their microservices all in Java, rest of our group uses .Net Core

gusty girder
#

wait im kind of confused here

rustic pebble
#

.NET is nice

gusty girder
#

so learning web development with python and java is bad?

zealous siren
#

javascript != java

quick cargo
#

^

zealous siren
#

web development is broken into two pieces, frontend which is code that runs in browser, the backend which is run on the server

gusty girder
#

oh ok

zealous siren
#

frontend is all HTML/CSS/Javascript

rustic pebble
#

Kind of

gusty girder
#

and what are the backend options?

rustic pebble
#

many

zealous siren
#

backend can be whatever you want to be, Java, Javascript, .Net, Python, Rust, Go to name a few

rustic pebble
#

Every major language has an http framework

gusty girder
#

so is python good for this

rustic pebble
#

final?

zealous siren
#

can be, yes

gusty girder
#

is it meant for web development?

quick cargo
#

its used ALOT

zealous siren
#

meant for, no, acceptable choice, yes

quick cargo
#

things like instagram, dropbox etc... all use python backends

gusty girder
#

ive to look for a web development course on udemy or something else

rustic pebble
#

things like instagram, dropbox etc... all use python backends
@quick cargo instragram uses node probably

zealous siren
#

all major companies backends are probably in smattering of languages

quick cargo
#

Instagram runs on Django

zealous siren
#

depending on which group designed that microservice(s)

#

which is why you develop HTTP Microservices, then you don't have to give a crap about what a backend is written in

rustic pebble
#

@quick cargo wow didn't know that

zealous siren
#

like Discord uses both go/rust for backends

#

and I think python for some stuff too

quick cargo
#

i dont think they use go anymore

rustic pebble
#

I think discord has developed some of its backend on c++

#

Not sure

quick cargo
#

last time they used Rust and Elixer

zealous siren
#

CF8, I'm sure they haven't convert 100% to Rust

#

apparently you work in corporate, you know how that goes

#

we will get to that microservice, you know, at some point

quick cargo
#

tbf its like some banks still using languages from 20 years ago or more

zealous siren
#

like we still have microservices we haven't converted from .Net Frameowrk -> .Net Core

rustic pebble
#

COBOL

quick cargo
#

yeah lol

gusty girder
#

netflix runs on flask

zealous siren
#

and java

rustic pebble
#

react + clustered node is bae

gusty girder
#

thanks a lot guys all my doubts have been cleared

zealous siren
#

if you are learning, Javascript is not bad language to start with

gusty girder
#

The Social Network inspired me on checking out web development

zealous siren
#

you can use it as both frontend and backend (shudder)

gusty girder
#

yeah sure im planning on learning js

#

after some time

rustic pebble
#

Javascript is not really beginner friendly it has a c-like syntax and loads of moving parts

gusty girder
#

as i have finished the python basics and stuff

zealous siren
#

Sure but after you get over it, it's swiss tool box web language

gusty girder
#

so wont it be crazy to start js another language immediately

rustic pebble
#

Yea

#

I never properly watched a tutorial on javascript

#

I legit picked it up after learning python immediately

zealous siren
#

Sure, it's harder then python, but for web, I'd say if you wanted to learn a language, it's pretty much mandatory

rustic pebble
#

and then I just expanded upon it

zealous siren
#

esp with whole "Full stack developer" trend going down

#

aka, let's get 2 for price of 1

gusty girder
#

huh

rustic pebble
#

Just learn react-node and you can call yourself a fullstack dev

gusty girder
#

flask is based on python right

quick cargo
#

flask is python lol

gusty girder
#

so what do you guys think

#

when should i start learning another language

rustic pebble
#

Once you need it

#

One thing brings the other

#

When you get into the whole web development world you will need to learn the rest so you will be physically challenged to do so

gusty girder
#

kay

native tide
#

@gusty girder what do you exactly mean?

gusty girder
#

huh?

native tide
#

What languages do you already know?

#

@gusty girder

gusty girder
#

just python

#

and a small bit of java

native tide
#

So after you learned python what area did you specialize in?

gusty girder
#

well somehow i stumbled upon discordpy bots

#

and spent some time on that

#

then i thought of building apps

native tide
#

Well I guess that counts as machine learn and AI

gusty girder
#

and tried learning kivy

#

built a really simple app which i have to convert to an apk

native tide
#

Err not gonna lie man your kind of all over the place 😬

gusty girder
#

ikr

#

im like totally 💥

native tide
#

Are you like very good in at least one of those areas?

#

Like good enough to make a whole YT tutorial on it

gusty girder
#

then ig interested in web dev and planned to make a personal website

native tide
#

Woah man let’s take it easy for a second 😅

gusty girder
#

im like multitasking lol

native tide
#

Be careful with that

gusty girder
#

like when i learn one thing i discover another thing and get interested on that

native tide
#

Normally people who multitask and try and learn 5 things at once don’t tend to do so well

gusty girder
#

ik

native tide
#

Unless of course you learn well like that

gusty girder
#

i just cant seem to stay and finish off one thing

#

recently i saw The Social Network and got interested in web development

native tide
#

That’s one thing a LOT of programmers say is the worst thing you can do

#

You should try and learn at least ONE thing and get very good at it after that you can move on

#

It’s almost like learning an instrument

gusty girder
#

kay

native tide
#

If I start playing trumpet and get into it

#

But then I find another instrument let’s say the sax

#

You start leave the trumpet for the sax

#

But then you leave the sax for the Clairinet

#

You get the point

gusty girder
#

yeah

#

exactly what im doing 😅

native tide
#

But if you keep doing that you’ll never learn how to play one song on any instruments

#

Same thing goes with programming

#

I was like you before but thankfully I saw a video about biggest mistake a programmer make and I learned I should stick to on thing

#

So if you keep doing that with programming you’ll never learn how to create one program in any of the areas

gusty girder
#

yeah

native tide
#

I used to do the same thing when I was in 4th grade

gusty girder
#

wow you started coding in 4th?!

native tide
#

Yeah

#

I’m in 8th now

gusty girder
#

due

#

dude

#

same here!!!

native tide
#

I learned 4 programming languages throughout middle school

#

Oh dang someone that”s actually my age 😂😂

gusty girder
#

i just finished 8th

#

im 14 actually

native tide
#

I’m turnings 14 this year

gusty girder
#

Oh dang someone that”s actually my age 😂😂
ikr finally someone my age

native tide
gusty girder
#

ok

fickle fox
#

hey guys is there a way to limit user like that he cant see some buttons or texts?

tired root
#

Use permission levels

cold anchor
#

What’s the JavaScript code?

tired root
#

I am trying to ignore a block when parsing a file with python-markdown. Anyone got an idea? I have tried writing an extension, but if I just echo the block back, markdown garbles it later.

#

If I parse with the other tool first, which puts out html, then markdown puts that inside a <pre> tag

#

@opal kelp It probably sends it twice due to your if logic

#

if (!data.error and data.title) will probably fix it

#

It is also bound to document click

#

why not just bind it to the click function of the button?

#

onlick='function()'

#

I also wouldn't use jquery.. write JS not jquery

cold anchor
#

why did you wrap the whole thing on a document.click?

#

don't need that

tired root
#

...

cold anchor
#

also jQuery is totally valid and tons of websites use it, there's no shame in using it

#

change $(document).click(... to $(document).ready(...

#

right now you're binding your event handler to the form every time the document is clicked

#

so if you click the page 5 times, you'll send 5 requests when you click "submit"

tired root
#

no, bind it to the button

cold anchor
#

almost, but you can change your submit handler back to $('#form_register').on('submit', ... to make sure you catch any way that the form is submitted

#

no, you need the form

#

and add the ID to the form, not the submit button

#

just have 1 $(document).ready(... call and put everything in there, and make sure your different forms have different IDs

gusty girder
#

hi

#

which django tutorial is better?

#

teluskos or coreys

#

in youtube

#

??

hollow lark
#

Doesn't matter

#

Just start coding

gusty girder
#

im planning on buying a course from udemy

#

python and django full stack web developer

#

it teaches how to use javascript,html,css,jquery and python

#

what do you guys think?

hollow lark
#

That's good

#

You can build a lot of sites with that

#

But jQuery is getting outdated, you're better off learning React

#

Here's a much better learning route

gusty girder
#

but then that doesnt teach django

hollow lark
#

You don't need Django or Python

#

You can write server side code with JavaScript

#

1.) You won't have to learn two languages
2.) NodeJs is more powerful and used more in the industry (from my experience)

gusty girder
#

kay

hollow lark
#

I forgot this is a Python sever LOL. My bad everyone.
But still, learn Nodejs brainmon

rustic pebble
#

Web developmen channel is not strictly limited to python frameworks

gusty girder
#

thanks this course has many more reviews than the previous one

vagrant jackal
#

Hey guys, I'm learning django and have something that I can't solve, maybe someone could help me 😀
So, I started my studies with the "Python crash course 2nd edition" book, and one of the projects are a little learning log, where you can add topics and entries...
So, if you enter topics/ it shows all the topics, and then you can select one of them and add some entry
I'm improving the code a little bit, I already put a sidebar, and now im struggling in one thing
I want to show the topics in that sidebar, which I already did with this code in my view

def index(request):
"""The home page for Learning Log."""
topics = Topic.objects.filter(owner=request.user).order_by('date_added')
context = {'topics': topics}
return render(request, 'learning_logs/index.html', context)

But there is a problem, if I go to the page topics/1 (for example, topic 1), then the topics doesnt appear anymore in the sidebar, because the view index was not triggered instead the topic view is... I dont want to put this same line of code " topics = Topic.objects.filter(owner=request.user).order_by('date_added') " in all my views.

There's another way of doing this? Thanks!

#

In my base.html I have this to show the topics

{% for topic in topics %}
<li>
<a href="{% url 'learning_logs:topic' topic.id %}">{{ topic }}</a>
</li>
{% empty %}
<li>No topics have been added yet.</li>
{% endfor %}

native tide
#

Can anyone suggest any use cases where Flask is preferred over Django

#

I am learning Falsk instead of Django, I have a hunch it's the right oneand better but both have their own uses

snow sierra
#

Flask is a like Startapp application and gateway from backend to front.. django is a more functionaly, powerful framework..
my advice to you is Learn flask, it is easy and understandable 🙂 in future you can easily move to django 🙂

#

QUESTION:
i have api based json lists,.. i want save each item to my local DB...

def index(request):
profile_id = 12345
profile_api = 'xS12POxJeUQkLweR6huob'
r = requests.get(f"https://aexample.com/user/{profile_id}?&key={profile_api} ")
rdata = r.json()
return render(request, 'tp_template/tp_profile.html')

if we use print (rdata['name']) in console printed profile name. everythong works fine...

just want this profile name and other data from API store to my local DB ..

ornate dew
#

Hey

#

I want to start a new project where I make a chat application using sockets

#

What python module should I use to make the UI

#

or should I even use python

#

for the UI

#

I'm down to learn Javascript just for this , but is it worth it ? Or can I make a nice UI with Python

native tide
#

@ornate dew If you're making a chat application, then yeah you'd have to use javascript, unless you'd want people to refresh the page to see new messages (bad design). You could still have Flask or Django run the application on the backend.

ornate dew
#

Ok

#

Which one is better , flask or django?

#

for the backend

quasi ridge
#

impossible to answer

#

that's like saying "is a Miata better than a panel truck"

ornate dew
#

Ahahah okay

quasi ridge
#

flask's big advantage is that it's kinda small and simple

ornate dew
#

I'll go with flask then

native tide
#

both of them are excellent, it all depends on what you want to do. flask comes with a lot less and you have to explictly define more stuff. django comes with a bunch more and has a bit more of a learning curve, but has a "batteries included" approach so much of what you need is already included

quasi ridge
#

django's advantage is that has a lot of handy stuff built in , particularly if you're using a SQL database

native tide
#

yep

#

it comes with its own ORM

ornate dew
#

😮

#

I'm planning on using mySQL

#

for login and chat history

native tide
#

at the same time though, flask has flask-sqlalchemy which isn't hard to use (I've done multiple projects with both)

ornate dew
#

cant I just use a cursor

native tide
#

if you know how to use one, it doesn't take much effort to learn the other

ornate dew
#

for SQL

native tide
#

I never worked on that low of a level for what I've done, but I think you can do that with any orm

#

they just give you an abstraction layer to treat tables as classes, rows as objects, and columns as attributes/properties, bringing OOP into it

ornate dew
#

ooh

native tide
#

yes its another thing to learn, but once you get it you can do stuff much faster and simpler

#

you can even give the models methods, just like a normal object would have

native tide
#

I have a question regarding aggregating ORM data for visualization and 'condensing' events. I'm keeping track of API calls to a django server, and every request becomes its own object internally, recording multiple things about it but most importantly in this context- the time it was received. All of this data will be kept for some period, and then automatically purged after a month. My question comes in two different pieces:

  1. How could I visualize this data, through something like matplotlib? The graph would take the total number of API requests in 15 minute periods, and then aggregate that data into a graph. And of course, there would be different views for hourly/daily. Is this something built in or that exists somewhere?

  2. Even after the objects are deleted to conserve space, there should be some lower resolution form of the analytics data left over for historical reference. Again, does anything exist that does this?

Making this functionality wouldn't be a problem, but I'm just asking to see if anything like this already exists just so I'm not needlessly spending time reinventing the wheel. The data visualization/analysis aspect of web dev work is completely new to me, any input would be appreciated. If this question is better suited for #data-science-and-ml I move it there instead. Thanks.

gusty girder
#

is using js better than using python for backend web dev

lapis charm
#

Hi can anyone help me with an error in my server

#

414 Request-URI Too Large

#

i get this when i try to load a page which has large number of data passed to it using get

peak thicket
#

In aiohttp after starting a web server, is there a way to remove the:

======== Running on http://0.0.0.0:8080 ========
(Press CTRL+C to quit)

or not?

young crane
#

In Flask, is it possible to do something where I have the website path localhost:5000/dashboard. Going to that page will show a list of options that are always changing (never static data on this page) that you can select. Ltes say that there are 3 items. A, B, and C.
A has a value of 1000
B has a value of 217
C has a value of 9887

If I click on A it would go to the link localhost:5000/dashboard/1000
B would go to localhost:5000/dashboard/217
C goes to localhost:5000/dashboard/9887

They all load the same base template, but they all get data from my database. The data will vary between each value (1000, 217, 9887)


@app.route("/dashboard/????")
def pageView():
  return render("baseFile.html", data=MyDatabaseLookup(????))

Because the data on the page will always be changing I cant just hardcode it like


@app.route("/dashboard/217")
def pageView():
  return render("baseFile.html", data=MyDatabaseLookup(217))
#

Please ping me if you can help 🙂

#

Or ping me if this is not possible to let me know

remote anchor
#

Hey, everybody! I've been trying to develop an application to list all hrefs in a webpage.

For some reason I am able to get all hrefs from the interpreter, but not from running the script. I have no idea and I'm stumped. Tried troubleshooting.

I'm working with the Selenium module in Python. In the interpreter I set up a variable

links = driver.find_elements_by_id("IDNAME")
for elm in links:
print(elm.get_attribute("href"))

^ this prints all of the links in the interpreter, but if I run a script with the same code, nothing is printed and the application ends.

Anyone know what's going on?

cinder juniper
#

Hey @remote anchor can you update your nickname according to our nickname policy seen in #rules it just needs to be mentionable

remote anchor
#

@cinder juniper name updated

cinder juniper
#

Thanks, although you just needed to set a nickname for the server. Didn't have to change your discord name

remote anchor
#

@cinder juniper Good to know for next time. Thanks for bringing it to my awareness

cinder juniper
#

What do you mean when "running the script" how are you doing that?

remote anchor
#

python ./scriptname.py
^contains the same code that I run in the interpreter, but does not print href links. The python ./scriptname.py ends without printing links unlike the interpreter running the same code

cinder juniper
#

If you add a print('Test') to the top, does that print out?

remote anchor
#

@cinder juniper Correct

cinder juniper
#

Hmm, if that is printing but not the rest then I'm really not sure. If there's no errors then really it should be working

remote anchor
#

i know, right 😦

cinder juniper
#

I haven't worked with Selenium so idk if it could be because of that

remote anchor
#

Thank you for trying to help, @cinder juniper

native tide
#

If i wanted to add input validation to my website, would i put the code client side or server side?

fickle fox
#

hey guys, i was wondering is there way to show some buttons only to certainpeople, like menages with role system?

#

in flask

ornate zodiac
#

could somebody help me with html? (basics)

#

I need this

#

to be like this

#

<ul class="zakupy">
<ol start="5">
<ol type="I">

 <li>chleb</li>
 <li>mleko</li>
 <li>maslo</li>
 <li>szynka</li>
 <li>ser zolty</li>
 <li>dzem</li>
 <li>cukier</li>

</ul>

#

<style>
ol.zakupy {
list-style: upper-roman;
}
</style>

cloud path
#

hey guys

#

the upload of a picture with flask doesn't work

#

am i doing wrong?

#
if form.validate_on_submit():
        if form.picture.data:
            picture_name = secure_filename(form.picture.data.filename)
            file_path = os.path.join(app.root_path, 'static/profile_pics', picture_name)
            form.picture.data.save(file_path)
            current_user.image_file = picture_name
        current_user.email = form.email.data
        db.session.commit()
        return redirect(url_for('account'))
gilded monolith
#

@fickle fox probably you can modify the jinja template if an user is logged in, have some permission or an attribute that you define

nimble epoch
#

@cloud path instead use this

if form.picture.data:
pic = form.picture.data
pic.save(“static/pictures/” + secure_filename(pic.filename))
user.picture = pic.filename

#

This might work

cloud path
#

thanks for your reply, but nothing it still doesn't work :/

gilded monolith
#

something like: {% if current_user.is_authenticated %} your buttons things {% endif %}

cloud path
#

it no gives me error

#

but nothing appears

gilded monolith
#

id perform the checks also in the views because im paranoid

nimble epoch
#

This works well but have you used enctype in the form tag?

cloud path
#

yes i have

#

and this is my flask form:

#
class UpdateAccountForm(FlaskForm):
    email = StringField('Email', validators=[DataRequired(), Email()])
    picture = FileField('Carica l\'immagine di profilo', validators=[FileAllowed(['png','jpg'])])
    submit = SubmitField('Aggiorna')

    def validate_email(self, email):
        if email.data != current_user.email:
            user = Account.query.filter_by(email=email.data).first()
            if user is not None:
                raise ValidationError("Email già utilizzata.")
nimble epoch
#

Use your form.picture.data in a separate variable because once i used it like form.picture.data.filename it gave me and error

#

Try it like

var = form.picture.data

cloud path
#

alright (y) i'm trying, i'll let you know

nimble epoch
#

Ok

#

And of course be sure that the file is jpg or png type

cloud path
#

yeah it is

#

maybe instead of form.picture.data, is it form.picture.file?

nimble epoch
#

No to access the form data from the inputs in flaskform the data is tru

cloud path
#

alright

#

btw i tried like that

#
if form.picture.data:
            pic = form.picture.data
            picname = secure_filename(pic.filename)
            pic.save("static/profile_pics/" + picname)
            current_user.image_file = picname
nimble epoch
#

If its an html form we use request.form[“var”]

cloud path
#

but still nothing

fickle fox
#

Ooh okay i will try it

nimble epoch
#

Ok ok

cloud path
#

i'll try to do other things thanks anyway

nimble epoch
#

Yw

gilded monolith
#

@fickle fox dunno if that's best practice but it's what i use to show buttons in a navbar to registered users

cold anchor
#

I'm saving files locally with this and it's working:

saved_filename = f"{str(uuid.uuid4())}_{filename}"
fpath = os.path.join(current_app.config['UPLOADS_DIR'], saved_filename)
upload_file.save(fpath)
#

and my UPLOADS_DIR is defined like this:
UPLOADS_DIR = os.path.join(APP_DIR, 'static', 'uploads')

#

APP_DIR = os.path.abspath(os.path.dirname(__file__)) # This directory

fickle fox
#

oooh, I am trying to make 'forum' with possibility for moderators to move posts to different sections, to edit and delete posts, and things like that, and i dont want other users to have that option as well

cloud path
#

@cold anchor thanks for sharing, i'll try like that too

cold anchor
#

if that doesn't work for you I can share the full view & model code

gilded monolith
#

Probably Flask have an extension for permission or you can use pass a boolean to the view

#

I think you still need to check if an user can or cannot do something, because you would only show/dont show the button, but they would still be able to do the action by crafting themselves a request

#

Someone more versed in this than me can probably chip in

cold anchor
#

I have an app that does this hold on I can get some sample code

#
# myapp/views.py
...
from myapp.auth import super_admin_required

...

@blueprint.route("/private")
@super_admin_required
def do_private_logic():
    # protected logic here
    return {'status': 'ok'}
...

# myapp/auth.py
from functools import wraps

from flask import current_app, abort
from flask_login import current_user


super_admin_roles = set([
    'sadmin',
    'uadmin',
])


def super_admin_required(f):
    @wraps(f)
    def decorated_function(*args, **kwargs):
        if not current_user.is_authenticated:
            abort(401)
        if current_user.role not in super_admin_roles:
            # TODO: 403
            abort(401)
        return f(*args, **kwargs)
    return decorated_function

# app.py
...
@app.errorhandler(401)
def render_401():
    # another option could be to redirect to an allowed page
    # return redirect(url_for('app.public'))
    return render_template('401.html')
#

then just add a "role" column to your users that contains a string

vague vigil
#

Following up from my azure deployment issues yesterday. I gave GCP a try to see if it was maybe a platform issue. Total time on the back end to perform the operation was 3-4 seconds, total time for client to send then receive was 16.9 seconds. This is down from 22 seconds on Azure, but up from 3 seconds locally.

rustic pebble
#

network bottleneck maybe?

cold anchor
#

can you click on that request in the network table and check the "timings" breakdown of it?

vague vigil
cold anchor
#

nice!

#

so the "waiting" amount of time lines up with what you're seeing on the server, then

#

and the content download is fast

#

it might be worth looking up what the "request sent" means in chrome to help nail down where it's hitting the bottleneck

vague vigil
#

Sounds great, thanks both of yall!

rustic pebble
#

I think the request sent is the time a promise takes to resolve since all requests are promises

rustic pebble
#

I am guessing it might be a network bottleneck then

#

Try running from another device, maybe using data connection

#

It also might be that promise thing

#

What is the request body?

vague vigil
#

I'm sending an image and receiving back a small json object with text and coordinates of where that text is located on the image.

rustic pebble
#

Since you are sending an image an upload might take time

vague vigil
#

brb

rustic pebble
#

Here is a resolution I can recommend you, although not sure how much it can reduce the time it takes to upload it: Convert the image to base64 and send it as a plain string, then decode it server side and get the image object

cold anchor
#

what is the content-length value in the request headers for that request?

vague vigil
#

sorry about the delay - I had a meeting. I'm going to do a little more reading on headers and then I'll have that info for you

cold anchor
#

it's in the "headers" tab of that request, near the "timings" tab

vague vigil
cold anchor
#

21mb transfer over 14 seconds is just under 2mb/s upload speed

#

so it seems like it's just a slow connection

vague vigil
#

So does this mean that my browser (client, right?) is sending the entire image back to the server?
As in client -image-> server -image-> google_vision -results-> server -results->client?

#

If so, then the solution would be to send the coordinates (4 x,y points) to the back end, have it send the image (like it is already doing) to google_vision, then return the results

zealous siren
#

yea, connection is slow

twilit zenith
#
    <h3>Recent Vouches</h3>
    {% for vouch in vouches %}
      <h2>Author : {{ vouch['author'] }}</h2>
      <h2>Member : {{ vouch['member'] }}</h2>
      <h3>Vouch Value : {{ vouch['value'] }}</h3>
      <p>Comment : {{ vouch['comment'] }}</p>
    {% endfor %}
#

at first when i run flask app it displays everything

#

but when i refresh page documents disappear completly

#

i am using mongodb/pymongo

#

am i doing something wrong?

#
profiles = collection.find().sort('_id', pymongo.DESCENDING)
vouches = collection2.find().sort('_id', pymongo.DESCENDING)

@app.route("/", methods=['GET'])
@app.route("/home", methods=['GET'])
def home():
    return render_template('index.html', profiles=profiles, vouches=vouches)


if __name__ == '__main__':
    app.run(debug=True)
fresh dock
#

@twilit zenith i'm not super familiar with pymongo but I think I know the problem. i'm guessing collection.find().sort() is a generator function, which can only be iterated over once. Therefore, defining it at the top means it's a one-shot and done

#

put lines 1 and 2 inside def home

fickle fox
#

guuys i am trying to make registration form

#

is this good or would you change something?

#
def registrate():
    render_template('register.html')
    if request.method == 'POST':
        name = request.form['nickname']
        email = request.form['mail']
        passwords = request.form['pw']
        submitpw = request.form['rpw']
        ph = PasswordHasher()
        hash = ph.hash(passwords)
        if ph.verify(hash, submitpw) is True:
            new_user = Users(
                            name=name,
                            mail=email,
                            pw=hash)
            db.session.add(new_user)
            db.session.commit()
        else:
            print('Try again')
    else:
        redirect('register')```
warm spire
#

can i specify user agent, content type/length etc as data in a post request?

fresh dock
#

add a honeypot field to the form

#

an <input> that is hidden with css so a human user should never fill it out

#

name it something like "email-confirm"

#

then if you get data in that field you know it's a bad request and you should abort(418)

tired root
#

can i specify user agent, content type/length etc as data in a post request?
@warm spire That can be edited, do what @fresh dock said

fickle fox
#

ooh i never heard for honeypot

fresh dock
#

418 is "I'm a teapot" but I like to use it as a "no fuck you" error code

tired root
#

The correct return if you encounter a bot is 403 forbidden though, but I'd just send a 200 OK to throw the bot off

fickle fox
#

i ll google it thanks 😄

#

weird now i dont see inputs at other pages

#

yeah idk why tho i cant see input fields

tired root
#

did you hide all inputs?

#

you need to make an extra css class

fickle fox
#

i have different fields in different html pages, is there a way to select them?

#

wait exstra css class?

#

i cant see them in an older page

tired root
#

If you write something like css input[type=text]{ display: none; }that applies to all inputs

#
.email-confirm{
  display: none;
}```
fickle fox
#

is that done with wtf flask fields?

tired root
#

in css...

fickle fox
#

ohh will check it now

fresh dock
#

you'd have

#
<input id="email-confirm" name="email_confirm">
#

in the html

#

then

#

in css

#
input#email-confirm {display:none}
#

@tired root @fickle fox ^

tired root
#

if you do with a class or id makes no difference in this case

fickle fox
#
@app.route("/registrate", methods=['GET', 'POST'])
def registrate():
    if request.method == 'POST':
        name = request.form['nickname']
        email = request.form['mail']
        passwords = request.form['pw']
        submitpw = request.form['rpw']
        ph = PasswordHasher()
        hash = ph.hash(passwords)
        if ph.verify(hash, submitpw) is True:
            new_user = Users(
                            name=name,
                            mail=email,
                            pw=hash)
            db.session.add(new_user)
            db.session.commit()
            return redirect('/posts')
        else:
            render_template('/registrate')
    else:
        redirect('register')

<form class='formm' action='/registrate' method='POST'>
    <input id="nickname" type="text">
    <br/>
    <input id='mail' type='email'>
    <br/>
    <input id='pw' type="password">
    <br/>
    <input id='rpw' type='password'>
    <br/>
    <input id='sbm' type='submit'>
</form>```
#

i cant load /registrate page

#

and its doing something with code at other sides

#

idk what would be wrong

#

this is error

cold anchor
#

you're not returning in the last redirect and render_template calls

fickle fox
#

ooh wait wait

#

oh now its good

#

thanks

native tide
#

So it doesn't look like digitalocean allows you to register a domain name. Who should I use? The only other site that I know of is GoDaddy

tired root
#

A service that allows you to edit your DNS entries

#

and that is located in your country is probably a good consideration as well

#

Example: if you own a trademark and are located in the EU, a registered domain in the US won't do you any good if your trademark is not worlwide

#

someone could register the tm in the US and snatch the domain from you

#

other way around applies too

#

Probably not an issue for you right now, but can if the project is successful

#

@native tide

native tide
#

Hi there, is there any way for a Django parent template to always have a variable? My navbar shows a number next to notifications (just like facebook). I could wire it through every view but I feel like there is a better way. Thank you.

#

@tired root I'm US-based and might site will be also

native tide
#

Someone recommended namecheap so maybe I'll try that

native tide
#

Leaving this example here to show you what not to do.

html

<span class="spanny" style="some-prop:10px;">This is very spanny text</span>

css

span {
  some-prop: 10px;
}

span.spanny {
  some-prop: 10px;  
}
molten quarry
#

Spent the last 4 hours trying to figure out why
{% if user.username == model_object.owner %}
wouldn't evaluate to true. They both printed the same username.

Turns out I was comparing a string with a user object, but the __str__ made me think it was a string. Just needed to compare 2 objects...

{% if user == model_object.owner %}

Wasted half my day

wild thunder
#

guys, see if you understand this error:
werkzeug.routing.BuildError: Could not build url for endpoint 'edit_post'. Did you forget to specify values ['id']?

my .py script:

@app.route('/news/edit/<int:id>', methods=['GET', 'POST'])
def edit_post(id):
    post = BlogPost.query.get_or_404(id)
    form = Post()

    if request.method == 'POST':
        if form.validate_on_submit():
            post.title = form.title.data
            post.author = form.author.data
            post.content = form.content.data

    elif request.method == 'GET':
        return render_template('edit_post.html', post=post, form=form)

my .html file:

    {% block content %}
    <div class="container">
        <form method="POST" action="{{ url_for('edit_post') }}">
            <h1>Edit Post : {{post.id}}</h1>
                {{ form.csrf_token }}
                {{ wtf.form_field(form.title) }}
                {{ wtf.form_field(form.author) }}
                {{ wtf.form_field(form.content) }}
            <input type="submit" value="submit">
        </form>
    </div>
    {% endblock %}
molten quarry
#

I'm really new to Django, but in my forms, I've been directing the action attribute to url routes, not to view functions.

#

I can't read all your code, but it looks to me like you're directing it to the function. Though you have that @app.route line and I'm not knowledgeable enough to know what that does.

quasi ridge
#

url_for is supposed to take a view function, and return ... the url for it 🙂

onyx crane
#

the thing gets created like this:

{% if message.tags == 'error'%}
            <script>M.toast({html: "{{message}}", classes: 'blue-grey darken-2', displayLength: 3000});</script>
        {% endif %}
sleek mortar
#

i have a couple of /api routes. i want my /api route only accessible by post requests but i dont wanna go change every decorator to methods=["POST"]. is there a cleaner way to do it?
i use flask

amber moat
#
settings-bundle.js:1 
Failed to load resource: net::ERR_FILE_NOT_FOUND urlbar-bundle.js:1 
Failed to load resource: net::ERR_FILE_NOT_FOUND components-bundle.js:1 
Failed to load resource: net::ERR_FILE_NOT_FOUND background-common-bundle.js:1 Uncaught TypeError: Cannot read property 'getUILanguage' of undefined
    at Object.<anonymous> (background-common-bundle.js:1)
    at r (bundle.js:1)
    at Object.<anonymous> (background-common-bundle.js:1)
    at r (bundle.js:1)
    at Object.<anonymous> (bundle.js:1)
    at r (bundle.js:1)
    at Object.<anonymous> (bundle.js:1)
    at r (bundle.js:1)
    at Module.<anonymous> (bundle.js:1)
    at Module.<anonymous> (bundle.js:1)
browser.html:1 Not allowed to load local resource: chrome://vivaldi-data/css-mods/css
DevTools failed to load SourceMap: Could not load content for chrome-extension://odbfpeeihdkbihmopkbjmoonfanlbfcl/sourcemaps/contentscript.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
#

when opening an HTML resource of vivaldi

amber moat
#

Vivaldi is an electron app

amber storm
#

Anyone know is the twitter API allows an app to tweet on the behalf of a user?

#

I am using the python-twitter library

viral sphinx
#

Hey guys for Django, idk why but I can’t seem to get updates on MySQL workbench when my website is on production

#

Do we have to make migrations after we deploy the app even though we can done it locally(but to a remote database, a the configurations are the same during deployment)

#

Have done it locally ****

wild thunder
#

i'm using bs

#

i tried 'pull-right'

#

but no result

ornate dew
#

Hello

#

so i'm done with the backend for my messaging app

#

but for the front end

#

I dont know what to do

#

I cant use css

#

I dont understand it

#

is there a way to get a quick UI

#

easily?

native tide
#

its about as easy as it gets

ornate dew
#

Oh

#

thank you

native tide
#

I use it all the time, including right now lol

#

its good

ornate dew
#

There are themes I can just snatch right away?

native tide
#

yes

#

go on bootswatch, and you'll see links for the css. you can either get it from a CDN, or download it locally

ornate dew
#

do I need to dl bootstrap?

native tide
#

you don't have to download it locally, just depending on what you're doing its sometimes the better option. like I have a web app running on a raspberry pi in my room and the css is local; if the internet ever went down the application would have no css. that kind of thing

#

in most use cases you can just use the link. I think twitter runs/funds the CDN

ornate dew
#

My web app will run on my Cloud Server

native tide
#

then yeah, just linking to it would be the best choice

ornate dew
#

using <link></link>

#

?

#

im dogshit at front end html stuff

#

lmao

native tide
#

you dont have to include the css from the bootstrap website btw. if you're using a theme, it contains all of the css. just saying lol

#

np lol, we all started there

#

don't know offhand exactly, let me check fast

ornate dew
#

okok

native tide
#

I think the bootswatch website actually has the code too...

ornate dew
#

Ok

native tide
#

so just choose the one you want on bootswatch, plug the link in to the <head> and bingo bango

#

anyway I threw enough at you I think lol

ornate dew
#

One last thing

#

I have these html elements

#
<ul id="messages"></ul>
<input type="text" id="myMessage">
<button id="sendbutton">Send</button>
#

How do I change their position

#

in the page

native tide
#

thats where the bootstrap components come in

ornate dew
#

I added the link

#

it changed colors and stuff

native tide
#

in your case, I'd look at the card, and form pages

#

it will get you started

ornate dew
#

Ok

native tide
#

theres a lot of templates to use so you dont have to reinvent the wheel generally

#

some hate it some love it... but its a pretty opinionated framework

ornate dew
#

I agree with you, I'm not gonna waste time on front end

#

so bootstrap is ❤️

native tide
#

if you just want it to work and dont mind a simple interface, yeah its perfect

#

I'll never stop using it

ornate dew
#

If I want to use css

#

in an html

#

file

#

how do I do it

#

rn

#

it just pops

#

oh i got it

#

its style

native tide
#

if you want to use the css elements, its pretty much all classes

gusty sage
#

hello is anyone here into web scraping using beautiful soup and requests?

slender adder
#

@gusty sage Won't say I'm 'into it' but I've used it for work.

balmy knoll
#

here is the part of the html?

native tide
#

@gusty sage y did quiet a bit of scraping

native tide
#

Do any one know email verification in flask

cold anchor
#

Like confirming that the user owns the email they signed up with?

native tide
#

@cold anchor yes

cold anchor
#

do you already have a way to send emails from your server?

native tide
#

Hmm I'm using sendgrid because port 25 is blocked in gcp

elfin tinsel
#

I don't know if the cat is right

#

I am asking here.

#

I am making a discord bot using Flask

cold anchor
#

make a token for a user in your db then send it to the user's email and ask them to click a button to verify which is a link that takes them to your server with the token you made for them

native tide
#

Oh then can I also create a var in db as ‘is_verified=True/False‘

elfin tinsel
#

Hello

pliant falcon
#

Hey guys.. there is a limit of using JS with django? or django is open to work with all javascript methods?

obsidian prawn
#

can someone teach me python

#

i know c#

#

LOGICsteveXD.say "see"

#

lol

elfin tinsel
#

I am getting this error

Running on http://127.0.0.1:5000 (CTRL + C to quit)
[2020-05-13 20:05:46,471] Running on 127.0.0.1:5000 over http (CTRL + C to quit)
[2020-05-13 20:05:49,235] ERROR in app: Exception on request GET /
Traceback (most recent call last):
  File "F:\Python Discord\lib\site-packages\quart\app.py", line 1807, in handle_request
    return await self.full_dispatch_request(request_context)
  File "F:\Python Discord\lib\site-packages\quart\app.py", line 1829, in full_dispatch_request
    result = await self.handle_user_exception(error)
  File "F:\Python Discord\lib\site-packages\quart\app.py", line 1074, in handle_user_exception
    raise error
  File "F:\Python Discord\lib\site-packages\quart\app.py", line 1827, in full_dispatch_request
    result = await self.dispatch_request(request_context)
  File "F:\Python Discord\lib\site-packages\quart\app.py", line 1875, in dispatch_request
    return await handler(**request_.view_args)
  File "F:\Python Discord\lib\site-packages\quart\utils.py", line 70, in _wrapper
    result = await loop.run_in_executor(
  File "F:\Python 3.8.2 (x64)\lib\concurrent\futures\thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "F:/PyCharm Python Works/OpenCityBot/Bot/bot.py", line 71, in hello
    return "Hello from {}".format(bot.user.name)
AttributeError: 'NoneType' object has no attribute 'name'
Executing <Task pending name='Task-15' coro=<ASGIHTTPConnection.handle_request() running at F:\Python Discord\lib\site-packages\quart\asgi.py:78> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x000002186495A160>()] created at F:\Python 3.8.2 (x64)\lib\asyncio\base_events.py:422> cb=[_wait.<locals>._on_completion() at F:\Python 3.8.2 (x64)\lib\asyncio\tasks.py:507] created at F:\Python Discord\lib\site-packages\quart\asgi.py:26> took 0.156 seconds
[2020-05-13 20:05:49,393] 127.0.0.1:62021 GET / 1.1 500 29031 167003
#
my_presence_per_day.start()
add_guild_to_json.start()
app.run(host="127.0.0.1", port=5000, debug=True, use_reloader=False, loop=bot.loop)
bot.run(TOKEN)
#

Please help

vagrant adder
#

That's happening because your bot.user is None

#

And None object doesn't have .name attribute

#

Make an if statement that tests whether bot.user is None or not

zealous siren
#

are you trying to mix flask and Python?

fickle fox
#
def registrate():
    render_template('register.html')
    if request.method == 'POST':
        name = request.form['nm']
        email = request.form['mail']
        passwords = request.form['pw']
        submitpw = request.form['rpw']
        ph = PasswordHasher()
        hash = ph.hash(passwords)
        if ph.verify(hash, submitpw) is True:
            new_user = Users(
                            name=name,
                            mail=email,
                            pw=hash)
            db.session.add(new_user)
            db.session.commit()
            return "registrovani"
        elif ph.verify(hash, submitpw) is False:
            return render_template('register.html')
        else:
            return 'Site crashed, reload it and try again'
    else:
        return render_template('register.html')```
#

guys i am trying to reddirect user if hashed pw and submited one doesnt match, but its conttstantly giving me error

#

how can i fix it

#

maybe to do with js pop up msg or something

#

but firstly to fix this

cold anchor
#

what's the error?

fickle fox
#

argon2.exceptions.VerifyMismatchError: The password does not match the supplied hash

cold anchor
#

I'm confused why you're going through the trouble of hashing both of them if you just want to verify that they match

#

why not if passwords != submitpw:

fickle fox
#

ooh thanks

#

btw how does google value sites privacy?

#

u see that pop up block

cold anchor
#

you're not using https, which is fine in development

#

you can just ignore it

fickle fox
#

ooh okay

ionic plover
#

Does anyone know if it's possible to route and render Pelican through a Flask development server or am I just going about this wrong?

#

and just use the pelican development server

tired root
#

@ionic plover What is Pelican?

ionic plover
#

It's a static website generator.

tired root
#

Doesn't make much sense then

#

Why deliver static html through a dynamic system,?

#

Just set up nginx or apache and you are good

#

Or asked differently: What do you expect flask to do with the html?

ionic plover
#

Yeah like I got Pelican set up with a theme and all to create a blog website but I thought I could get it running through a flask developement server to serve the website to display on the web browser.

tired root
#

If you need a plain html quick server, python -m http.server on the directory you want to serve

zealous siren
#

or just grab Nginx container, throw your JS/HTML into there and set it loose

native tide
#

Is this the best place to talk about hosting services?

#

cuz i want to know if Netlify is actually that good

#

What are the pros and cons of Netlify?

tired root
#

@zealous siren Totally overblown

#

For a bunch of html files on a local pc the built-in python http server is more than enough

zealous siren
#

Depends if it’s local or not

#

And if you have container support already

native tide
#

ok

lavish prismBOT
#

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.
• Don't ask if anyone is knowledgeable in some area, filtering serves no purpose.
• 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.
• Be patient while we're helping you.

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

gritty quail
#

Hi, I am studying Information Technology in Brazil, but in my country there is not much content about programming language. I was wondering if you can send me pdfs of books that have great content on programming languages, especially if it is focused on html / css and C #announcements

tired root
#

We are not doing piracy here

#

!resources

lavish prismBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

tired root
#

here are some tutorials and stuff

gritty quail
#

So give me a good book

tired root
#

entitled much?

gritty quail
#

indicate some tutorials on youtube as well if you can, whatever you can to help. Thank you

tired root
#

I gave you a link with lots of tutorials, but we are not giving you books

gritty quail
#

Yes, I understand

#

Now, where are the links?

tired root
gritty quail
#

do you have links that teach html / css or c #?

native tide
#

I can't figure out what am I supposed to do. I am using DRF and I want to access some endpoint but show different result if a user created that resource and another result if some other user is accessing it. I'm using Session Authentication.

#

I can't figure out what am I supposed to do. I am using DRF and I want to access some endpoint but show different result if a user created that resource and another result if some other user is accessing it. I'm using Session Authentication.

tired root
#

Do you have google?

#

I mean, seriously, it is ok to ask for help, but you need to show some initiative as well

#

I gave you our collection of resources, read it, pick something and learn

#

This is a python discord, if you want to learn C#, this isn't the place

gritty quail
#

Yes, but you who program longer may know of a better option so that I don't waste time on unnecessary sites

#

If you don't want to help, I'll wait until someone with empathy helps me. Thank you

native tide
#

I cant comment about C#, but with HTML and CSS... It's been a very long time since I learned the basics of HTML, so its kind of difficult for me to think of a good modern resource. The main thing I can say is to make sure you're learning from an updated source.

https://developer.mozilla.org/en-US/docs/Learn/HTML

I would recommend mozilla docs for just about anything frontend webdev related. They will really be the authority on most things.

https://www.w3schools.com/

If you're looking for something that is less, "dive into the documentation", this site is pretty good for most frontend things as well, though Id avoid it for JS lessons tbh.

#

mainly because it will set you on a path to writing outdated JS.

fickle fox
#

Is it possible to run flask server and python codes from phone?

toxic marten
amber storm
inner ridge
nova storm
#

Okay wait @inner ridge

#

You can go for it

#

Or if you want to study with video lectures then you can find so many courses on udemy, where i learned it

calm pond
#

@amber storm guess I could help you with that

#

But can't really right now...... Tomorrow maybe

amber storm
#

it is the question mark messing with it, thanks for the offer tho!

calm pond
#

👍 recently built a complete web application with Django
So played quite a lot with it

nimble epoch
#

I dont get something in sqlalchemy Table object

#

In the following.c.followers,
What is c?

native tide
#

Is this doing my due dilligence assuming there is no profit on the site, and I have searched this much to try to identify the person but can only trace it to pinterest sharing. I imagine for someone who truly cared, they could dig deeper. My question, is it my due dilligence to care about finding the person who released their art and then made it such that when I search for the image, they are not the first thing that comes up. Because imo, if they chose not to do that, then there would be no way for them to not be credited. There would be no way for me to ignore a "do not use request" -- but when something is shared all over the internet to the extent that some things are, is it wrong of me to just clip some image and use it in in a web design, when I cant find the original artist because they have no site publishing it?

ornate dew
#

hello, does anyone know how I can run my flask app publicly?

#

rn its running on localhost

#

I have this that shows up

#

when I try to use Apache to run it on my cloud server

#

my stuff is in /var/www

native tide
#

hello, does anyone know how I can run my flask app publicly?
@ornate dew yea

ornate dew
#

😮

native tide
#

when I try to use Apache to run it on my cloud server
@ornate dew use nginx is easier than apache to run flask

ornate dew
#

nginx, how do I set it up

#

my cloud server is under Debian 9

native tide
#

nginx, how do I set it up
@ornate dew you are using which cloud

ornate dew
#

wdym which cloud

native tide
#

?

ornate dew
#

My OS?

#

it's Debian 9

#

Linux

native tide
#

Hmm

#

No

ornate dew
#

My Cloud Provider?

native tide
#

Yea

ornate dew
#

Digital Ocean

native tide
#

Oh ok

#

sudo apt install nginx

#

it's Debian 9
@ornate dew debian and ubuntu are mostly the same

ornate dew
#

oh

#

Alright thanks!

#

I'll follow that

native tide
#

@ornate dew for apache

ornate dew
#

screw apache

#

I already tried

#

doesnt work

#

this happens

native tide
#

@ornate dew oh ok

ornate dew
#

lol

native tide
#

Is it apache

ornate dew
#

Ya

native tide
#

Oh ok

ornate dew
#

ill try with nginx

native tide
#

I also run my flask in nginx

ornate dew
#

alright gimme a few minutes

#

ill try

native tide
#

Ok

ornate dew
#

is the virtual environment part necessary?

native tide
#

Hmm it's up to you

#

And forgot to tell you run your flask development server on port 5000

ornate dew
#

isnt that the dev port

native tide
#

@ornate dew Mmm for me I did all the steps it didn't work after changing the dev port in the mainfile.py it worked but in nginx I kept port 443

native tide
#

@ornate dew did it work?

static night
#

Have phpstorm autocomplete in html ?

native tide
#

Is it possible to upload (through ftp-transfer) a .db database and use it together with a flask/django website? Ie. make a working website offline and upload everything - will it still work?

gleaming herald
native tide
#

[do any one know how to make loop in flask (HTML) file

#

Haven't tried it myself, but have you checked out this guide?

#

@native tide thanks:)

#

Please report back if it solved the issue. I am still early in the course, so have not had the chance to test myself yet 🙂

nimble epoch
#

Anyone can explain to me the the primaryjoin and secondaryjoin in SQLAlchemy?(i dont get it properly)

grizzled crescent
#

Hello everyone ☺

I have a job in a company as a Python developer but I want to find another jobs for the week-end to make more money.

Do you Know where can I find short jobs while working at home ?

cold anchor
#

upwork might be a good place to start building a freelance portfolio

#

if you want to go further than that I'd recommend registering as a company and building a website and advertising/reaching out to local businesses

grizzled crescent
#

@cold anchor did you try upwork ?

cold anchor
#

I haven't personally, their rates for somebody just starting is way lower than I would charge- I use my network to find freelance opportunities

#

surprisingly, I've also had people reach out about freelance from reading my blog posts, so that's another avenue you could use

pulsar ivy
#

I tryed freelancer, i cant find a job

#

I need to show some projects that i am not total beginner :(

#

So i will try to make website for free

#

And use it as reference

grizzled crescent
#

You pay someone to read your blog posts @cold anchor ?

cold anchor
#

start with personal projects, things you want to build, you don't need to just do free work

#

no, I don't pay anybody to read my posts, they're all available on medium

pulsar ivy
#

I am now making something like forum, tho whenever i made small change at code i mess up something else :(

cold anchor
#

writing tests might help with that!

grizzled crescent
#

Did you earn money with freelancer @pulsar ivy ?

pulsar ivy
#

Nope

#

Never

#

I never got actual job in there

#

So i am just in contact with experienced people in this field, they are navigating me

#

I cant wait to get first income lemon_hyperpleased

zealous siren
#

@gleaming herald that’s more #414737889352744971 question. Likely with 10k WSS, you will need to spin out more instances and include a load balancer

#

So I’d get your FastAPI going in container

gleaming herald
#

That I am doing now too @zealous siren

#

But the thing is if I restart the RESTAPI Code

#

The websocket file can accept more connections

#

And 1000 websocket per instance is a little too less?

zealous siren
#

Not necessarily

#

Are websocket and Rest API mixed in same server?

#

If so, I’d separate them if possible

cold anchor
#

☝️

#

they do 2 very different jobs and you'll likely see better performance from both if you separate

zealous siren
#

But to scale, likely you will need multiple containers and load balancer possibly with right hand side request routing

gleaming herald
#

But to scale, likely you will need multiple containers and load balancer possibly with right hand side request routing
@zealous siren https://blog.jayway.com/2015/04/13/600k-concurrent-websocket-connections-on-aws-using-node-js/

#

Here is one example without containers

#

but they use node.js

cold anchor
#

they also use a very big and expensive server

#

which server are you using?

gleaming herald
#

My configuration is 8 cores

zealous siren
#

Ops is very trial and error using hard numbers

gleaming herald
#

with 16GB Ram

cold anchor
#

another cap is the number of max open files on the server, max connections can't exceed that

#

run the ulimit command to see what this number is

zealous siren
#

Problem being is GIL

#

Gunicorn isn’t multiple processes just multiple threads

cold anchor
#

👍

gleaming herald
#

Gunicorn isn’t multiple processes just multiple threads
@zealous siren I'm using uvicorn

#

The workers which is configurable uses processes

cold anchor
gleaming herald
#

AFAIK

zealous siren
#

Cool

gleaming herald
zealous siren
#

But I assume there is built in LB handling

gleaming herald
#

another cap is the number of max open files on the server, max connections can't exceed that
@cold anchor How does WS is connected to max open files

zealous siren
#

Gunicorn uses uvicorn

gleaming herald
#

@cold anchor How does WS is connected to max open files
@gleaming herald I remeber getting error of too many files open once or twice

cold anchor
#

for each connection your server needs to open another file, if you hit the max number of open files, you can't accept another connection

gleaming herald
#

Aah

zealous siren
#

Again if your server is dying under load, at work, step 2 is toss a load balancer at it and spin up multiple instances

#

Even if it’s on same server

gleaming herald
#

Another problem would be

#

If one container has accepted a ws connection

#

next time it should go to the same container

zealous siren
#

Why?

gleaming herald
#

Because your open connection would be inside that container

#

If you go to different container it would not have your connection and probably start a new connection to wsserver

zealous siren
#

Load balancer would keep open socket with same container

gleaming herald
#

Ah Okay

#

I guess that would be devops team would handle

zealous siren
#

Which is what I am

gleaming herald
#

I was just curious and wary about

#

why the concurrent connection number is soo low

#

Is it normal

#

or I was doing something wrong?

zealous siren
#

Websockets are “heavy”

#

Compared to HTTP

cold anchor
#

I guess my question for you is: what are you optimizing for? (practically) are you hitting errors when your thousands of users connect? are you trying to future-proof your scale and keep your costs low?

gleaming herald
#

I guess my question for you is: what are you optimizing for? (practically) are you hitting errors when your thousands of users connect? are you trying to future-proof your scale and keep your costs low?
@cold anchor the latter

zealous siren
#

For a lot of languages, it’s garbage collector

gleaming herald
#

I can do a hard limit by seeing that if number parallel connections are more than 1000 directly tell them

#

but that's more like scapegoat

#

I wanna scale well

cold anchor
#

tbh, I'm of the mindset that you should deploy your app and let this problem happen, then solve it

gleaming herald
#

That will happen

#

considering the userbase

zealous siren
#

We run into same problem with C#

cold anchor
#

this is what I would call a "good problem" to have- you have so many users that you're hitting errors in something underlying your app code

gleaming herald
#

We run into same problem with C#
@zealous siren Can you expalin more

#

this is what I would call a "good problem" to have- you have so many users that you're hitting errors in something underlying your app code
@cold anchor That's what I was wondering

zealous siren
#

When you try and scale inside same “process”, the garbage collector is What causes the load issues

gleaming herald
#

TBH it's a whatsapp bot and since callbacks of WhatsApp are in RESTAPI I'm building it

zealous siren
#

Thus separate processes and load balancer

gleaming herald
#

And since the client would be Amazon or Uber Bot

#

You can easily expect atleast 10K parallel connections

#

Thus separate processes and load balancer
@zealous siren Aaah

cold anchor
#

but can you expect 10k connections right now? do you have amazon or uber as a customer today?

gleaming herald
#

but can you expect 10k connections right now? do you have amazon or uber as a customer today?
@cold anchor Yes

cold anchor
#

great- then this is a problem worth solving lol, just wanted to confirm that

zealous siren
#

What cloud you using?

gleaming herald
#

What cloud you using?
@zealous siren Currently we have our own servers

#

great- then this is a problem worth solving lol, just wanted to confirm that
@cold anchor Exactly

zealous siren
#

Ehhhh

cold anchor
#

you have racks of servers you're keeping on prem?

gleaming herald
#

Thus separate processes and load balancer
@zealous siren So keeping API And WSSERVER seperate would help?

#

you have racks of servers you're keeping on prem?
@cold anchor Yes

cold anchor
#

wow

gleaming herald
#

More related to Security

#

With so wide clientele it's a rich company

#

LOL?

cold anchor
#

so at my last job we decided to break out the WS server from the http servers and use a totally different language

#

none of us were experts in a framework that did a great WS job so we learned elixir quickly and made a separate websocket service

#

we had similar issues and contracted the author of the phoenix framework to help us scale our connections

gleaming herald
#

Woah

#

And?

cold anchor
#

and it worked like crazy, our memory and cpu load went way down and we had clear signals for "you need to spin up a new server and put it behind the LB now"

#

because the limit was the # of open files on the server

gleaming herald
#

The problem would be I'm using a AI model in WSServer and i'm pretty sure migrating a complete service would be a bad idea
And ML/AI is done much easily on python then on another server

#

because the limit was the # of open files on the server
@cold anchor I'm pretty sure it's the same issue

#

would need to see how to increase this limit

cold anchor
#

have your AL/ML service be an http API that sends messages to the WS server

#

make them two distinctly separate services

#

by the time I left that job we had just passed 1MM concurrent connections

gleaming herald
#

OMFG

#

That's a dream I'd like to achieve now

#

Using elixir you say?

cold anchor
#

phoenix/elixir

gleaming herald
#

and increasing the maximum open file limit

#

on server

cold anchor
#

and use rabbit's advice too: have a load balancer

gleaming herald
#

Aah! Okay

#

have your AL/ML service be an http API that sends messages to the WS server
@cold anchor I wish I could

cold anchor
#

what's the constraint stopping you?

gleaming herald
#

So the AI Model is for Chatbot

cold anchor
#

we had an NLP service that was done in python and communicated to the WS service to send messages

gleaming herald
#

So the thing is the NLP Service is context dependent

#

So once you said hello

#

it starts your intent document

#

and would fill all the slots

#

like if you say Hello, book a cab

#

it would start the service and ask for locations

#

so websocket is easy in this case

#

as I can just do recv() on start and when required location I can do it again

#

if that makes sense

cold anchor
#

yeah that makes sense

#

but there's no reason you still can't separate the services

#

even if they're context dependent

neat flower
#

Hey, are there any Django wizards around?

gleaming herald
#

even if they're context dependent
@cold anchor so how do I create a rest api where everytime I get the request I would know what are the past responses and this should be the reply

cold anchor
#

so the way we did this was that the server was stateless and every time it got a message from a user it would update and persist the context of the conversation to the database

gleaming herald
#

so the way we did this was that the server was stateless and every time it got a message from a user it would update and persist the context of the conversation to the database
@cold anchor Aah

#

Any resources you sugges

#

I 'm not aware of this methodology

cold anchor
#

sorry, all this stuff was home-brewed so it's not something I can share more details about under my NDA

gleaming herald
#

LOL

#

I get it

cold anchor
#

though I can suggest that you take the "context" you have in your NLP server and imagine it was a blob of data: how would that data look? what questions do you need to ask it?

#

you can store blobs of data just fine, so that was the general method we used

#

just a dict filled with the context of the conversation

gleaming herald
#

Yeah

#

just a dict filled with the context of the conversation
@cold anchor

hi_flag = False
message = await websocket.receive_bytes()
if message == "Hey":
    hi_flag = True
    reply = f'hey, there {user_id}'
    await websocket.send_bytes(reply)
    message = await websocket.receive_bytes()
    if message == "hey":
        reply = f'Hey you already said Hi ! WTH !'
        await websocket.send_bytes(reply)

if message == "Goodbye":
    if not hi_flag:
        reply = 'Hey You did not say HI !'
        await websocket.send_bytes(reply)
#

So for a code like this

#

I would just replace the websocket receive bytes

#

and I would parse through the blob of data

#

everytime I get a request?

neat flower
#

I'm building a survey site, where a user is being shown a set of images, which are pulled from a database. The user then classifies those images to one of two categories. After this, the user is taken to a new view, where they are being shown those same images and they have to draw on top of them. Now, I have to save these drawings and associate them with the survey participant. Question is, does it make sense to create a Form for the drawings or how would I pull that data from the user's interactions?

cold anchor
#
conversations_by_user_id = { ... } # this is the mock database

message = await websocket.receive_bytes()
conv = conversations_by_user_id[user_id] # this is the db lookup
hi_flag = conv['hi_flag']
conv['messages'].append(message)
if message == "Hey":
    ,,,
#

so part of your logic would include getting and updating the conversation state

gleaming herald
#

Aah
Kinda makes sense

cold anchor
#

I would suggest imagining a conversation without AI

#

how would you model, save and fetch the conversation and messages of just a user<>user conversation?

#

since an AI is just another client of the conversation

zealous siren
#

Wrjh what country you in?

#

Being on premise is a killer

#

But if you need Load Balancer, I’ve used Kemp with good results

#

And they have virtual appliances

#

You could roll your own with Nginx likely

gleaming herald
#

But if you need Load Balancer, I’ve used Kemp with good results
@zealous siren Would take a look

#

Wrjh what country you in?
@zealous siren We have servers mostly in US
But also backup in Italy and India

#

how would you model, save and fetch the conversation and messages of just a user<>user conversation?
@cold anchor So AI is not used for replying the message it is used to find the meaning and ask appropriate questions so we can get data

#

Like imagine you come and say Hello, I am rdbaker
The ai would recognize that rdbaker is name and wouldn't ask for name that is name slot would be filled
So the script would go on to next slot that is what is your age

cold anchor
#

right, and what data does that AI need to make that decision?

#

that's the question to answer in order to find out how to store the context of your conversation

gleaming herald
#

right, and what data does that AI need to make that decision?
@cold anchor It just needs the utterance

cold anchor
#

but it also needs to know about past utterances too, otherwise how would it know the user already said hi? (for example)

zealous siren
#

I can’t imagine doing this completely on premise

gleaming herald
#

LOL

#

You would rely on AWS?

#

I guess i'll probably shift to that from prem servers

zealous siren
#

Azure

#

For us

gleaming herald
#

but it also needs to know about past utterances too, otherwise how would it know the user already said hi? (for example)
@cold anchor Aah that's part of the NLP Layer which I have applied for patent

zealous siren
#

Like AWS/Azure have really capable load balancer you could just deploy

#

This conversation would be like 30 seconds long

gleaming herald
#

Like AWS/Azure have really capable load balancer you could just deploy
@zealous sirenAWS is so big

zealous siren
#

And?

gleaming herald
#

Understanding it would take soo long

#

I feel
There are million things available

#

Do one thing in wrong way they will charge IDK What

#

Anyways Amazon is not known for it's UI/UX Experince

zealous siren
#

Sure, downside to on premise is amount of time wasted dealing with this

gleaming herald
#

LOL

#

Agreed

cold anchor
#

I have a resource that helped me understand using AWS pretty securely in terms of network security if that would help

#

haven't used azure though

gleaming herald
#

I have a resource that helped me understand using AWS pretty securely in terms of network security if that would help
@cold anchor Yes Please

cold anchor
gleaming herald
#

💯

cold anchor
#

very cool

gleaming herald
#

As said Elixir is among top

#

But GO is also a easy replacement

cold anchor
#

interesting that they had such memory usage with elixir

#

after hiring the author to contract with us, we got rid of those problems

zealous siren
#

We do websockets in c#

#

But still after a while, you want to load balancer and setup additional servers just for stability and deployment reasons

#

We like azure since most of PaaS services have private network stuff

gleaming herald
#

@cold anchor Looks like there is a limit on open files and keeping them on same server would have affected it more

#

We like azure since most of PaaS services have private network stuff
@zealous siren Still AWS is still a mammoth in PaaS

cold anchor
#

you can bump that, I think we had 50k or so per server

gleaming herald
#

Like it dominates the market a lot

#

you can bump that, I think we had 50k or so per server
@cold anchor Damn! Thanks a lot

vast rover
#

Hi everyone i'm, trying to create a simple webpage that shows the cookies that are stored in firefox. Until now I have not been able to show anything cause the console shows a few errors. Does anyone could help me? What am i missing or i did wrong? I'm leaving the code in a pastebin link. Thanks in advance to everyone who's gonna help me. https://pastebin.com/ac0dPbzY

zealous siren
#

Firefox will not show website all the cookies

#

wrjh, Sure, AWS is largest in market share and if it works for you, great, we are Azure because we are C# shop and it made sense for us to go with Microsoft cloud

#

but we run some python and go

#

despite Microsoft branding, they try really hard to be language agonistic and mostly succeed

#

and there is GCP but man is it limiting

fickle fox
#

Is there any good tut for making login system, I already made registration system

gleaming herald
#

despite Microsoft branding, they try really hard to be language agonistic and mostly succeed
@zealous siren Aah! okay

#

looks like azure has improved a lot over time

#

would definitely check it out

zealous siren
#

9SGx11, figure out which oAuth provider you want to use and integrate wiht it

#

Google/Facebook are common ones for consumers

#

Discord is option if you are doing discord oriented setup

knotty seal
#

If I have two submit buttons in a form and I want both of them to return form data back to a flask display function but after some processing, send to different render templates, is there a variable I can embed in the submit form input to differentiate the buttons?

fickle fox
#

okay

knotty seal
#

@fickle fox You could also try the flask mega tutorial

fickle fox
#

where can i find it?

knotty seal
#

He makes a functioning blog with a login section, comments, database

fickle fox
#

ooh thanks

knotty seal
#

np 😉

fickle fox
#

i am rn trying to figure out how to open post in different page

knotty seal
#

Are you using flask?

patent cobalt
#

@kindred marsh Any reason for spamming an invite link?

fickle fox
#

yes

kindred marsh
#

I was not spamming

#

I just want people to join

patent cobalt
#

Yes, that's what spamming is

kindred marsh
#

Sorry

#

I wanted to ask

fickle fox
#

I am trying to think how to understand where user clicked and where to capture 'POST' METHOD

#

mostly rn trying to open post

#

later on i ll creat db for comments

kindred marsh
#

@patent cobalt Do you teach python here or just answer questions of people who are learing python

fickle fox
#

something like "like" button...

knotty seal
#

@fickle fox Understood. You can do an if request.method == "POST":

#

Here is a form I am working on... similar concept...

@app.route("/order", methods=["GET", "POST"])
def order():
  if request.method == "POST":
    drinkType = request.form["drinkType"]
    milkType = request.form["milkType"]
    drinkSize = request.form["drinkSize"]
    sugarAmt = request.form["sugarAmt"]
    extras = request.form["extras"]
    myDrink = MyCoffee(drinkType, milkType, extras, sugarAmt, drinkSize)
    myTuple = myDrink.returnData()
    return(f"{myTuple}")
  else:
    return render_template("order.html")
patent cobalt
fickle fox
#

wait are u trying to display it later or store it in db?

cloud path
#

hey guys, is there a way to specify the maximum file size or the maximum image size through FileAllowed from flask-wtf?

knotty seal
#

@fickle fox - I can replace the return(f"{myTuple}") with a return render_template

#

I only have that there for testing

fickle fox
#

ooh okay

#

i will try to make it

knotty seal
#

Here is an example from when I was learning it...

def entry():
  global bookDetails #global instantiation required. Otherwise there is an error about using the variable before declaring it.
  if request.method == "POST":    
    bookName = request.form["book"]
    authorName = request.form["author"]
    rating = request.form["rating"]
    #create a tuple
    bookTuple = (bookName, authorName, rating)
    #create a dict
    myDict = {"book": bookName, "author": authorName, "rating": rating}
    x = bookDoc.insert_one(myDict)
    #create a list of tuples
    bookDetails.append(bookTuple)        
    #print(bookDetails) <-- Used in debugging
    #return render_template("table.html", book=bookName, author=authorName, rating=rating) <-- Used in debugging
    return render_template("table.html", bookTuple = bookDetails)
  else:
    bookDetails = [] #clear any existing tuples
    return render_template("entry.html")```
#

I was using mongoDB in that app

fickle fox
#

now i get error 'str doesnt exist'

#

or something like that

#

oh wait i need string

knotty seal
#

😛

fickle fox
#

{% block head %}
<title>{{post_opens.title}}</title>
{% end block %}
{%  block body %}
<p name ='title' id='title'>{{post.title}}</p>
<br/>
<p name = 'content' id='content'>{{post.content}}</p>
<br/>
<p name = 'author' id='author'>{{post.author}}</p>
{%  endblock %```HTML
#
    post_opens = BlogPost.query.get_or_404(id)

    if request.method == 'POST':
        post_opens.title = request.form['title']
        post_opens.content = request.form['content']
        post_opens.author = request.form['author']
        return render_template('post.html')
    else:
        return render_template('post.html', posts=post_opens)```
#

here what would i need to make it functional? or to display text? @knotty seal

knotty seal
#

You need to pass the data into the HTML template you're rendering... eg:

def post_open(id, author):
    post_opens = BlogPost.query.get_or_404(id)

    if request.method == 'POST':
        post_opens.title = request.form['title']
        post_opens.content = request.form['content']
        post_opens.author = request.form['author']
        return render_template('post.html', title=post_opens.title, content=post_opens.content, author=post_opens.author)
    else:
        return render_template('post.html', posts=post_opens)
#

Then...

{% extends 'base.html' %}

{% block head %}
<title>{{post_opens.title}}</title>
{% end block %}
{%  block body %}
<p name ='title' id='title'>{{ title }}</p>
<br/>
<p name = 'content' id='content'>{{ content }}</p>
<br/>
<p name = 'author' id='author'>{{ author }}</p>
{%  endblock %}
fickle fox
#

ooh

#

let me try it

#
    {% for post in posts %}
        <h2>{{ post.title }}</h2>

        {% if post.author %}
            <h3>By: {{ post.author }}</h3>
        {% else %}
            <h3>By: N/A</h3>
        {% endif %}
        
        <p>{{ post.content }}</p>
        <a href='/posts/delete/{{post.id}}'>Delete</a>
        <a href='/posts/edit/{{post.id}}'>Edit</a>
        <p id='time'>{{ post.date_posted }}</p>
        <a id='open' href='/posts/post/{{post.id}}>'>Open post</a>
        <hr>
    {% endfor%}```
#

this is from what i need to access it

#

@knotty seal tho i dont see any difference between code in my edit button and that one up there

knotty seal
#

What is the >

#

Sorry @fickle fox -- The URL has a greater than sign

#

<a id='open' href='/posts/post/{{post.id}}>'>Open post</a> <<--

#

See the extra > after {{ post.id }}

#

I am also working on my coffee ordering app, so I apologise if I don't answer sooner

fickle fox
#

its okay

knotty seal
fickle fox
#

yeah it looks nice

#

jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'end'. Jinja was looking for the following tags: 'endblock'. The innermost block that needs to be closed is 'block'.

knotty seal
#

You're missing an {% endblock %}

fickle fox
#

learning programming is hard 😦

knotty seal
#

lol Tell me about it

fickle fox
#

NO QUITING

#

{% block head %}
<title>{{post_opens.title}}</title>
{% end block %}

{%  block body %}
<p name ='title' id='title'>{{ title }}</p>
<br/>
<p name = 'content' id='content'>{{ content }}</p>
<br/>
<p name = 'author' id='author'>{{ author }}</p>

{% endblock %}```
#

as i see i have endblock :v

#

soon

#

i see my victory

knotty seal
#

Okay @fickle fox - What is that html file called?

fickle fox
#

post.html

#

why?

knotty seal
#

{% end block %}

#

space

#

Should be {% endblock %}

frigid spindle
#

i cant get my bootstrap columns to align vertically. what am i doing wrong?

languid shard
#

I'm trying to make a flask web app with Flask Login with two types of users: student and manager. I'm not experienced with Flask Login (currently using session). I'm trying to use a mongodb atlas backend with flask.ext.mongoengine to store student and manager data. I'm currently using sqlalchemy. Each student starts out with a manager_id of NULL, but can change to a managers manager_id. I'm not sure how to replicate this behavior with a nosql db such a mongodb using FlaskLogin since it seems like there can't be multiple types of users. Any help would be helpful 😛

tired root
#

@languid shard Each user should have ONE role

#

And that role defines access

#

so student is 0, manager is 1

#

as value

#

having 2 values for each violates NF1

languid shard
#

How should I relate/reference a student to a manager?

tired root
#

with a n:m relationship table

#

or is it 1:n?

languid shard
#

1 to many i think

tired root
#

can one manager have many students or many managers have many students?

languid shard
#

one manager to many students

#

Isn't that sql though? I'm trying to shift to a nosql db

tired root
#

Why?

languid shard
#

Oh

#

didn't see your messag

fickle fox
#

@knotty seal i would neevr notice it thanks xD

#

now i have just to manage to display text

languid shard
#

There's a json file for each user that I want to store along with the sql table. Right now the sql table has the filepath as a column, but I don't think that's sustainable for deployment since heroku deletes files.

zealous siren
#

Why would you do that?

tired root
languid shard
#

I have dictionaries i need to persistently store

#

for each user

#

@zealous siren

tired root
#

Translate them to tables

zealous siren
#

Or use nosql JSON store

languid shard
#

Yeah I'm trying to transition to nosql. @tired root Hmmm that would get messy pretty quick i think. I'll try to pull up a sample json file

tired root
#

@languid shard Use whatever you want, I've linked you the SO discussion above

#

maybe it helps

languid shard
#
{"personal_info": {"name": "", "county": "", "district": "", "division": "", "category": "", "club": "test"}, "leadership": [{"year": "2020", "activity": "Test", "role": "E", "level": "Cl", "duties": "                    Responsibilities / Duties / Accomplishments\r\n                "}, {"year": "2020", "activity": "Vice President", "role": "E", "level": "Co", "duties": "Assist the President.\r\n                "}, {"year": "2020", "activity": "Group Leadership", "role": "A", "level": "Cl", "duties": "                    Responsibilities / Duties / Accomplishments\r\n                "}], "service": [], "awards": [], "career": [], "invitations": {}}```
#

Yeah it looks helpful

tired root
#

that is easy to translate into a database

zealous siren
#

Yea

tired root
#

Looking at this file just screams relational to me 😄

zealous siren
#

And even then, there is plenty of systems that will let you throw JSON at it and then select off of it

languid shard
#

leadership e.g is a list of dictionaries though

tired root
#

What db you are using, which type and to an extend what product, should always be governed by use case, not because some manager uses the nosql buzz word

#

Or serverless shudder

zealous siren
#

I use Azure CosmosDB/ Amazon has DocumentDB

#

Can’t Postgres do that as well?

languid shard
#

I've been using sqlite and flasksqlalchemy through cs50 ide, but thought it was wise to switch to mongodb since it stores data as json naturally

#

This is just a student project that I want to deploy on heroku

zealous siren
#

But scorcher is right, you can use relational database

languid shard
#

I learned sql like a month ago :). How do you store dictionaries? Would I need to make a table for leadership, service, etc... ?

zealous siren
#

Yes to second

languid shard
#

Hmm git reset --hard 🤣

polar pendant
#

hey

fickle fox
#
@app.route('/posts/post/<int:id>', methods=['GET', 'POST'])
def post_open(id):
    post_opens = BlogPost.query.get_or_404(id)

    if request.method == 'POST':
        post_opens.title = request.form['title']
        post_opens.content = request.form['content']
        post_opens.author = request.form['author']
        return render_template(
                                'post.html',
                                post=post_opens.title,
                                content=post_opens.content,
                                author=post_opens.author)
    else:
        return render_template('post.html',)```
#

{% block head %}
<title>{{ title }}</title>
{% endblock %}

{%  block body %}
<div class="cent">
<p name ='title' id='title'>{{ title }}</p>
<br/>
<p name = 'content' id='content'>{{ content }}</p>
<br/>
<p name = 'author' id='author'>{{ author }}</p>
</div>
{% endblock %}```