#web-development

2 messages · Page 51 of 1

queen bough
#

And create a model for each one.

frosty mauve
#

That's the gameplan (connecting them with other data as well)

queen bough
#

Right, need any other help with that?

frosty mauve
#

Let me see if this save works, I would be curious to see how you would do it but I feel confident in doing that if this save works

queen bough
#

Sure.

frosty mauve
#

saved, but pic didn't show up let me check something else

#

I think it is something with upload_to='/images'

#

The obj points to the /images but I didn't have image in there

#

So I need to just put all my images in there

queen bough
#

Where is upload_to? Is that in the ImageField definition in the model?

#

Surely you can simply change that?

frosty mauve
#

image = models.ImageField(upload_to='images/')

queen bough
#

Why isn't it media/?

#

Or is media reserved for the site images? I can't remember the distinction, exactly.

frosty mauve
#

No good reason, just trying to get this workign following an array of tutorials online

#

I guess I need to change my template now to fit media

queen bough
#

I see.

#

But yeah, a for-loop should do it.

frosty mauve
#

but I keep running into that same problem!

#

when I save it prefixes the url with media

#

and then the file path of image

#

image at /home/name/project/site/media/image.jpg

#

I set the newbook.image = path

#

when I type newbook.image.url I get media/home/name/project/site/media/image.jpg

queen bough
#

Hmm, this shouldn't be so diffcult. Let me quickly take a look.

frosty mauve
#

Appreciate it ❤️

queen bough
toxic marten
#

I need help with Flask. Im learning templates and im doing easy stuff. Someone can help me? Extends method of jinja doesn't work

#

Thats the app

#

app = Flask(__name__)


@app.route('/')
def index():
    return render_template('base.html')```
#

That is the base html file

#
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Homepage</title>
</head>
<body>
    {% block body %}
    {% endblock %}
</body>
</html>```
frosty mauve
#

@queen bough I think it's just a pathing issue, I will mull over this for a few more hours and let yyou know if I get it resolved 🙂

queen bough
#

@frosty mauve Sure, sorry I couldn't help any more.

toxic marten
#

And this is the derived.html

#


{% block body %}
<body>
    <p>HELLO</p>
</body>
{% endblock %}```
#

Thats pretty easy, but it doesnt work. Have i done some mistakes?

frosty mauve
#

@toxic marten Is it block body or block content?

toxic marten
#

Wait. uuhm which is the differences?

#

I know only body at the moment

frosty mauve
#

I have never seen body, just trying to help

toxic marten
#

👍

#

one sec, im going on my flask book

frosty mauve
#

I am working with Django and I am using some includes, haven't messed with extends yet but all the blocks have been block content

toxic marten
#

ok

#

my book says body is for content of the body tag, and content is for user defined page content

#

so should i use content?

frosty mauve
#

wouldnt hurt to try it real quick

#

I am still trying to figure out these webapps too 😛

toxic marten
#

👍

#

Flask is my first backend framework that i use. At first, i wanted to start with django, but a lot people say me that is better if i start with flask, cause it is more simple

frosty mauve
#

I think I probably should have done that 😛

#

I heard the same

#

bottle-> flask -> django

toxic marten
#

Exactly

candid moon
#

hello, i need some help, do you know how o put an expiring date to a post, so that after the expiring day the post autodeletes?

graceful linden
#

hi everyone! Hope someone can help. I'm making a practice project, it allows users to store their meds in a database and I'd like to add some sort of alarm or reminder (probably a notification, or email). I'm working with Django and I really don't know how to link the time selected with the notifications or email, or how to even add that functionality... Any guidance you could provide would be helpful.

proper hinge
#

You'd need to schedule a task to run in the future I imagine

#

I've not looked into how to do that with Django

#

However, Django 3.0 does support async AFAIK and generally it is possible to accomplish that with async, so that is one avenue to explore

#

Celery could also do this but it sounds like it may be overkill?

mighty herald
mighty herald
#

The bug comes every now and again and im not sure why. My code runs perfectly at times then randomly this shows up so I'm not sure.

rustic dragon
#

How to convert html animation to mp4?

opaque flax
#

I have a django model that stores the date & time when an object is saved. How can I get the total saved in the lpast hour, day, seven days, month and year? I think I can use pandas to do this but it's kinda heavy. What's the best way to do this?

errant spindle
#

how do i make the labels go directly above the rectangles

#

so that there's no space between the label # and the rectangle

nimble epoch
#

@mighty herald can i see your models?

#

@errant spindle use bootstrap or put every input with its label in a separate <div>

errant spindle
#

whats bootstrap

nimble epoch
#

This is a kinda library

#

You can even put every input and its label in the separate <div>

#

<div>
<label>label1</label>
<input type=“text” />
</div>

<div>
<label>label2</label>
<input type=“number” />
</div>

wise owl
#

Hey guys, I'm trying to understand urllib, and it feels like the simplest thing would be to request the active browser URL, and save it as a variable.. but the answers I got on stack didn't make much sense, or work when I tried to run them. Any tips?

nimble epoch
#

Read the docs

tired root
#

@nimble epoch Seriously?

nimble epoch
#

Any doubt

tired root
#

Someone who is deflecting questions with "use bootstrap" shouldn't be throwing rtfm around

nimble epoch
#

?

#

What is rtfm?

#

Ok got it

#

Whatsthe problem?

mighty herald
nimble epoch
#

GM

#

I thought that you did not use UserMixin but you have it

#

Fixed?

mighty herald
#

i have it but the user_login error is still showing up every now and again

nimble epoch
#

Can i see the whole error

mighty herald
#

its not showing up anymore. but it shows up sometimes

nimble epoch
#

Oh

mighty herald
#

On a different note i set up my schedule page and its functioning well except the same data is getting displayed on every users account even if im logged in diffferent accounts.

nimble epoch
#

You are not getting data from different user id probably

#

Does it show the whole data?

mighty herald
#

is it possibly because of line 26 where im query.all() ?

nimble epoch
#

Yeah you are adding whole data to dict

mighty herald
#

Ohh i see. Is there a what to only add the data basesed on current user id

#

way

nimble epoch
#

use query.filter()

#

db.query.filter()

#

sorry

#

db.query.filter_by()

mighty herald
#

db.query.filter_by(current_user.id) ?

nimble epoch
#

Better use db.query.filter_by(user=current_user.id)

#

If im right because i haven’t practiced flask for months

mighty herald
#

No worries ill try it out

nimble epoch
#

No You gotta use database name instead of db

#

Like Users

#

Schedules, ....

#

Or...

mighty herald
#

It worked! Thanks a lot man 🙂

nimble epoch
#

Yw

mighty herald
nimble epoch
#

Can you send the files that you are working whith because i cant find it like this

#

If possible

mighty herald
#

which files in specific?

nimble epoch
#

Your project

#

In a kind of cloud

#

Or sth

#

Line dropbox

#

Because i have never got this error

mighty herald
#

sure ill try dropbox

nimble epoch
#

Tnx

wide steppe
#

can I store some static files for my website in heroku, like a gnu dbm file

nimble epoch
#

I think yes

jagged lark
#

Sure you can

#

Heroku's dynos are small VMs, everything is technically possible

wide steppe
#

thanks

wintry lava
#

does anyone use Flask on Debian? I am having a hard time getting flask-sqlalchemy installed despite trying multiple things and searching for the error

jagged lark
#

Are you running it on a regular amd64 plateform, or on a arm device (like rpis)?

wintry lava
#

amd64

jagged lark
#

Okay

#

What have you tried so far?

wintry lava
#

here are the steps: python3 -m venv env. source env/bin/activate; pip install flask; pip install flask-sqlalchemy

jagged lark
#

Can you try to update setuptools and pip?

wintry lava
#

did pip install --upgrade pip

#

pip version is 20.0.2

jagged lark
#

And setuptools?

wintry lava
#

havent tried that yet. let me do so now

#

same error....it did update setuptools from 44.0.0 to Successfully installed setuptools-46.1.3

mighty herald
#

@nimble epoch how should i share you my files?

nimble epoch
#

There gotta be a share link

jagged lark
#

@wintry lava flask-sqlalchemy doesn't support 3.8 yet, the latest release is from Sep 24, 2019, before the release of 3.8 lemon_pleased

wintry lava
#

ahh!

mighty herald
nimble epoch
#

Oh ok let me check

mighty herald
#

Thank you

wintry lava
#

@jagged lark did the same steps with python3.7 ...same error 😦

#

python3.7 -m venv ~/.venv/flask

#

python --version
Python 3.7.7

#

command: /home/abc123/.venv/flask/bin/python3.7 /home/abc123/.venv/flask/share/python-wheels/pep517-0.7.0-py2.py3-none-any.whl/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmpehh2wnwl

#

actually let me update setuptools here too

#

nah..same problem

jagged lark
wintry lava
#

i guess it doesnt buildSQLAlchemy

#

will do. Thanks for looking!

#

yes it worked with : pip install --no-use-pep517 sqlalchemy and then pip install flask-sqlalchemy

nimble epoch
#

@mighty herald can i see the error page completely

#

A full screen shot might help

mighty herald
nimble epoch
#

I cant run your project

#

No i mean the error

#

I have you files but the error that it gives you

mighty herald
#

ohh okay

nimble epoch
#

Because i cant run your project

mighty herald
nimble epoch
#

No changes yet

#

I was looking for a file name

#

Sorry man thats a little complicated i still dont know why you get that error

mighty herald
#

Ill keep doing my research, but i appreciate your time man

nimble epoch
#

I really hope youll find it

mighty herald
#

Thankyou ill let you know when i do

nimble epoch
#

@mighty herald

#

I got sth but not sure

#

@login_manager.user_loader
def load_user(id):
return User.query.filter_by(user_id=id).first()

#

Of course be sure add this after app initialization

mighty herald
#

in my models file?

nimble epoch
#

Yeah

#

You have got your project so complicated and i guess that the orders are not correct

mighty herald
nimble epoch
#

Rhisnis because you dont have User and user_id

#

You gotta replace them base on you database

#

You add it like this

#

@login_manager.user_loader
def load_user(user_id):
return User.query.get(id=user_id).first()

#

If it didnt work

#

Use

#

@login_manager.user_loader
def load_user(user_id):
return User.query.get(user_id).first()

#

Whats the result?

mighty herald
#

I got it to work by deleting from flask import request that I wasn't using. Looks like it was missing a request_loader because of that.

nimble epoch
#

Wow

#

Fixed?

mighty herald
#

Yeah! Except knowing this issue that it keeps coming back im not so sure. lol

nimble epoch
#

You can fix that too😉

mighty herald
#

👍 thanks for your help again

hollow kestrel
#

would i come here for help web scraping?

native tide
#

I'm using css grids

modest elk
#

Hi

#

is there anyone online

#

i need a bit of help

native tide
#
    display: grid;
    grid-template-columns: 5fr 6fr;
    grid-template-rows: 1fr 10fr;
    grid-template-areas: "header header" "corpus corpus";
}
#

This is my code

#

But it always leaves a bit of space on the right of the grid

shadow hornet
#

make sure to ask your actual question with any issues and code you have @modest elk it makes people more inclined to help

modest elk
#

from flask import Flask, render_template, json
import requests, json

app = Flask(name)

@app.route('/')
def index():
r = requests.get('https://coronavirus-19-api.herokuapp.com/all')
data = r.json()
data = json.dumps(data, indent=2)
deaths = data['deaths']
return render_template('index.html')

if name == "main":
app.run(debug=True)

#

So i am trying to build a flask web app

#

to fetch this json api, and show it to my app

#

But i am finding it difficult

#

How i show it to the index.html

#

In js i would do for example {data.deaths}

rigid laurel
#
    data = r.json()
    data = json.dumps(data, indent=2)
    deaths = data['deaths']

This bit isn't right.

#

just ditch the second line

#

and it should work how you expect

#

dumps is dumping the json to a string. loads is loading a json form a string, but thats called by r.json(), so you don't need to do it

still briar
#

You should also pass varibles into the render call. For instance render_template('index.html', foo=42), or deaths in your case.

rigid laurel
#

yeah, thats how you want to show it in the template

#

you can pass the whole dict

#

you can do return render_template('index.html', data=data) then access data inside html by doing {{ data.deaths }}

modest elk
#

File "C:\Users\Irdi\Desktop\flask\app.py", line 12, in index
deaths = data['deaths']
TypeError: string indices must be integers

#

I get this error

#

i dunno why

rigid laurel
#

I explained why above

#

dumps is dumping the json to a string. loads is loading a json from a string, but thats called by r.json(), so you don't need to do it you want a dictionary, not a string. and r.json() returns a dictionary

wide steppe
#

I have a problem with heroku's ssl certification. When I deployed my site, the logs shows it is running perfectly but I can't connect to it because of some ssl issue

modest elk
#

dumps is dumping the json to a string. loads is loading a json from a string, but thats called by r.json(), so you don't need to do it you want a dictionary, not a string. and r.json() returns a dictionary
@rigid laurel When i remove deaths = data['deaths'] it loads the app but not the number of deaths. when i leave the line than it shows the error, i will try my best

rigid laurel
#

Let me try and make sure I understand your problem. You're trying to get the number of deaths from the json into the template right?

modest elk
#

Yes

#

That's right

rigid laurel
#

If so, you need to pass the dictionary result of r.json() into the template. For your case you can do that with something like

def index():
    r = requests.get('https://coronavirus-19-api.herokuapp.com/all%27')
    data = r.json()
    return render_template('index.html', data=data)

Then inside the template do

<div class="deaths">
    {{data.deaths}}
</div>```
#

Does that still give you an error @modest elk ?

modest elk
rigid laurel
#

Can you paste your template here?

modest elk
#

I know that i disturbed you i am sorry

rigid laurel
#

no its fine, if I didn't want to be helping you I wouldn't

#

so I don't mind at all

modest elk
#

<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<title>Hello, world!</title>
</head>

<body>
<h1>Hello, world!</h1>
<div class="deaths">
Death number:{{data.deaths}}
</div>
</body>

</html>

rigid laurel
#
def index():
    r = requests.get('https://coronavirus-19-api.herokuapp.com/all%27')
    data = r.json()
    print(data)
    return render_template('index.html', data=data)

Could you check that you're receiving the data correctly?

modest elk
rigid laurel
#

try thispy def index(): r = requests.get('https://coronavirus-19-api.herokuapp.com/all%27') data = r.json() return render_template('index.html', deaths=data['deaths']) then access it with {{ deaths }} inside the template

modest elk
#

Thank You so much

feral minnow
#

Nice

modest elk
#

return render_template('index.html', deaths=data['deaths'], cases=data['cases']) to show cases

#

Finally i got it

#

thank you so much @rigid laurel

pure token
#

You might also want to cache that if you are pushing this to public? 🙂

rigid laurel
#

Hm, I'm slightly confused. You should have been able to do it the first way with data.deaths/data.cases - but I'm glad I could help

#

not sure what was going wrong

#

but glad I could help

feral minnow
#

Guys I wanna ask you... So im trying to make a mp3 song downloader using flask but I don't know how i can upload the files to the users after its converted?

modest elk
#

You might also want to cache that if you are pushing this to public? 🙂
@pure token First time i did it with Svelte JS and it was easy, now that Charlie explained that to me i find it easier to do it in Flask too

#

Cache with redis?

rigid laurel
#

So you want the user to be able to click a button and download an MP3 @feral minnow ?

#

or the user uploads a file, you process it, and they get the file back?

feral minnow
#

I want the user to click a button and download the files

pure token
#

@modest elk at least make a function with a cache decorator or something that stores the value for a short duration so it does't do http request for every single page visit

modest elk
#

@modest elk at least make a function with a cache decorator or something that stores the value for a short duration so it does't do http request for every single page visit
@pure token That's a good idea, so i don't ping the api a lot

feral minnow
#

I tried <a href="{{filePath}}" download>Download File</a> but it didn't work

modest elk
#

For example update data every 5 min

rigid laurel
feral minnow
#

oh I will check it thx

#

I have to use config thing?

native tide
#
    display: grid;
    grid-template-columns: 5fr 6fr;
    grid-template-rows: 1fr 10fr;
    grid-template-areas: "header header" "corpus corpus";
}```
https://gyazo.com/4e11459ef064a32d2b5bb6957b3193ab
This is my code
But it always leaves this bit of space on the right of the grid, why is that?
rigid laurel
#

I think you can just do return send_file('path_to_your_file.mp3') or similar

#

might need to set as_attachment to True

feral minnow
#

oh

#

I will try it thx

#

@rigid laurel i tried send_file but its playing the video its instead of downloading it

rigid laurel
#

I think thats why you want as_attachment=True

feral minnow
#

oh

rigid laurel
#

I haven't actually used this myself

feral minnow
#

I have to put it after the file name?

rigid laurel
#

return send_file('path_to_your_file.mp3', as_attachment=True)

#

should be that

#

hopefully

feral minnow
#

I will try it

#

Oh it worked

#

Thanks a lot

rigid laurel
#

you can also set a filename with return send_file('path_to_your_file.mp3', as_attachment=True, attachment_filename="magic.mp3")

feral minnow
#

You mean that when it download the file it will download it with this name?

rigid laurel
#

yeah

feral minnow
#

nice...Thanks again you really helped me

earnest oak
#

Excuse me,

#

what's the difference between flask run and just doing python main.py

#

?

nimble epoch
#

Not sure but i think the difference is in their version

native tide
#

Hi guys!!! I am trying to find some help with this issue: I am usind Djangos paginator and when i click Next, instead of having the second page I receive my 'else' code

#

here my view and template:

native root
#

Your code does not make sure the q variable in the url persists through a next-page click

#

Because of that it becomes none, and you see what you're seeing. Your next page links should include the q value of the current page to make sure it persists appropriately

rich plaza
meager glen
#

Hey, Im trying to adjust the form-control width that bootstrap provides without messing up the other attributes. How can I do this? I have tried using a custom css class but then the website look changes completely.

nimble epoch
#

A question about Django

#

What is generic view or as_view() method AND what its used for?

nimble epoch
#

Ok what does it mean?

#

Whats the point?

queen bough
#

You'd have to understand views to be able to understand it.

nimble epoch
#

I understood views

#

I dont know what it does?

#

What is special about it

feral minnow
#

Guys anyone know how to center card from bootstrap

#

tried everything but nothing work????

nimble epoch
#

Try:
class=“row justify-content-center”

feral minnow
#

it workkkkkkkkkked

#

thx

nimble epoch
#

Yw

queen bough
#

It's also very dependent on your use-case, and thus difficult to explain out of context.

nimble epoch
#

So no difference which one i use?

#

Just some pros and cons, right?

meager glen
#

How can I center a button that is in a bootstrap card

nimble epoch
#

Try:
class=“row justify-content-center”

meager glen
#

That didnt work

queen bough
#

@nimble epoch Yup. Start with functions and refactor to classes if/when you need them.

meager glen
#

I centered the card with that but the button wont mov

nimble epoch
#

Put your button in a <div> and use that class in the <div>

#

Worked?

#

You can even use html <center> tag

meager glen
#

no it didnt work ill try the center tag

#

nope center didnt work

nimble epoch
#

Really?

#

Sometimes i think bootstrap doesn’t match with html and css

#

Even with itself

#

@queen bough i dont think that class based is useful, is it?

meager glen
queen bough
#

It is, very. When you want to connect it to a model then they are.

#

I can't remember all the reasons off the top of my head, but there's definitely a place for them.

#

Function-based are a lot simpler though.

nimble epoch
#

But you can use models in function based too

feral minnow
#

@nimble epoch its a photo of the website he's trying to make

#

He's trying to center the login button

nimble epoch
#

Add that class to your base div that has rounded the form

#

If didn’t get me send me the file to help

#

If got me so everything is alright

feral minnow
#

can you write me the code?

#

for the base div

nimble epoch
#

Can i see the code?

feral minnow
#

the problem is he's offline now

nimble epoch
#

Because i cant tell you where i meant

#

Oohh

#

You see the login form with the button?

feral minnow
#

yes

nimble epoch
#

A <div> gotta have surround it already

#

Add that class to that div

feral minnow
#

class=“row justify-content-center”

#

this one?

nimble epoch
#

Yeah

feral minnow
#

I remember that he tried that already but it didn't work

nimble epoch
#

Really

#

Sure?

#

Because i had the same form or kinda that but worked for me

feral minnow
#

oh

#

I will tell him to try that...but is there any other solutions?

nimble epoch
#

Surround your whole code after body tag with a div and and add that again to that div

#

This will probably work

feral minnow
#

oh ok

#

Thanks for help

nimble epoch
#

But that only way that i use whenever i use bootstrap

#

Yw

fresh dock
#

I add one goddamn logging function

#

"haha, fuck your performance stats"

nimble epoch
#

Thats great

fresh dock
#

I rolled back, delicately tried it again, then spent the next 20min unfucking it all

#

thank god for newrelic

feral minnow
#

Guys im trying to make a drop down button I copied the link from bootstrap but when I click at it nothing happen?

stable notch
#

i'm implementing a flask restful backend for a mithriljs webapp and trying to do auth. everyone says to use jwt, but is that a really a better solution than just flask-session?

#

it seems like a pain to have to mess with refresh tokens and local storage to get session to persist

native tide
#

like regular acco0unt auth ?

stable notch
#

yeah, normal accounts

#

jwt sounds like the better option, but i'm wondering if sessions that persist like normal session cookies are possible

fresh dock
#

@stable notch yes flask implements a cryptographically signed session cookie

stable notch
#

@fresh dock but would this be the correct use case for it? i'm not sure whether to use it or jwt plus refresh tokens

fresh dock
#

Oh

#

For a restful api where the client may not be implementing cookies, no

stable notch
#

it's acting as the backend for a single page app, so cookies are implemented

gilded dragon
#

So, I'm building a local hosted (on a raspberry pi) Django web server that will have a landing with different buttons on it, similar to a bookmarks or quick launch page, and the other app will be a page that controls an LED strip attached to my raspberry pi. I don't believe either of these apps require much at all, if anything, to do with database storage besides maybe for the superuser account (is that even stored in the database?). For now, can I basically skip over messing heavily with Models and the database stuff?

fresh dock
#

Me: pushes engine optimizations

#

Heroku: have a middle finger made out of your performance stats:

native tide
#
from flask import Flask, render_template, url_for, flash, redirect
from flask_sqlalchemy import sqlalchemy
from forms import RegistrationForm, LoginForm

app = Flask(__name__)
app.config['SECRET_KEY'] = '5174d34305f9ee68dadd141092a2985e'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db '

db = SQLAlchemy(app)```
is returning
```Traceback (most recent call last):
  File "/home/turtle/Documents/VSCode_Projects/flask_test/flask_test.py", line 9, in <module>
    db = SQLAlchemy(app)
NameError: name 'SQLAlchemy' is not defined```
native root
#

sqlalchemy != SQLAlchemy

valid cypress
#

I have 2 migrations of one Model that I removed. How can I remove/modify these migrations?

native tide
#

what is the easiest way to get the song name and current dj off this site? i tried lxml, but there is a stupid pop up.. so then i tried selenium to click the 'let me in' button. now im thinking that's overkill and it can be done with just lxml since the webpage is still visible behind the pop up... any hints as to how i could get them? https://plug.dj/4204681060305555241 is the link, and here is a screenshot (blue circle) of the variable i need with the pup up in the middle of the screen

proper hinge
#

They have an API

#

It's not documented though

#

I started working on documenting it myself but I don't think I covered anything related to this

#

Was more concerned with playlist management

#

Have a peek at the network requests to see if there's a useful endpoint

native tide
#

thank you

#

do you have a link to any of your playlist documentation? i may be interested in that as well

proper hinge
#

Also I don't think I wrote downn how the auth works anywhere

native tide
#

thank you so much!

white pewter
#

Can someone explain , i cant post in offtooic

tired root
#

What do you need an explantion for?

#

An IP address has a host part and a net part

#

The net part comes first and defines the network

#

the host part defines the number for that client

#

which part of the number is which, is defined by the subnet mask

#

@white pewter

white pewter
#

So

#

20 bit net id and 12 bit host id is random right

tired root
#

Random?

white pewter
#

Can i take 21 bit net id and 11 bit host id

tired root
#

you can, if the selected subnet allows it

white pewter
#

How can subnet allow

#

What is subnet

tired root
#

10.0.0.0/8 is a subnet

#

It's a private ip subnet

#

You can take this, and divide it into smaller chunks

#

So, 10.0.0.0/21 would be legal

white pewter
#

I dont get it. Leave it.

#

I cant understand

tired root
#

Have ever seen a subnet mask? They are written like this: 255.255.255.0

#

for example

white pewter
#

No i m newbie and this is from a book

tired root
#

You've never set the IP on your computer?

white pewter
#

Ifconfig shows my ip

tired root
#

yes and it also shows your subnet mask

#

That is the part that defines how many bits are for the network and how many bits are for the hosts

white pewter
#

But i dont understand anything except ip and dns

#

Oh

tired root
#

So an IP has 32 bits

white pewter
#

So subnet mask defines how much host id and net id

#

Oh got it

tired root
#

no

#

it defines the range of one network

white pewter
#

So what decides that net id is 20 bit and host id 12 bit

tired root
#

You

white pewter
#

I connect to internet and use

#

I never defined

tired root
#

forget the internet for a seconds, that is too complicated

#

lets stick with private IPs

white pewter
#

Ok

tired root
#

so for example 192.168.0.0

#

That is a net id

white pewter
#

Ok

tired root
#

It defines the network with the number 192.168.0.0

white pewter
#

Ok

tired root
#

Now I say I want 8 hosts in it

#

For 8 hosts, I need 10 IP

#

Why?

white pewter
#

Why?

#

I need 8 ip

#

8 host

tired root
#

Because netID is an IP and i need a broadcast IP which is always the last IP

white pewter
#

Oh

tired root
#

So, how many bits do I need for 10 IP?

#

3 is too little

#

so I need 4

#

32 bits - 4 bits = 28

#

192.168.0.0/28 = 14 max hosts

white pewter
#

Well i will complete the book then again come here , its little complicated

tired root
#

You are on linux right?

#

install ipcalc and toy around with it

#
user@ras:~ $ ipcalc 192.168.0.0/28
Address:   192.168.0.0          11000000.10101000.00000000.0000 0000
Netmask:   255.255.255.240 = 28 11111111.11111111.11111111.1111 0000
Wildcard:  0.0.0.15             00000000.00000000.00000000.0000 1111
=>
Network:   192.168.0.0/28       11000000.10101000.00000000.0000 0000
HostMin:   192.168.0.1          11000000.10101000.00000000.0000 0001
HostMax:   192.168.0.14         11000000.10101000.00000000.0000 1110
Broadcast: 192.168.0.15         11000000.10101000.00000000.0000 1111
Hosts/Net: 14                    Class C, Private Internet```
white pewter
#

Ok

white pewter
#

Can anyone explain how 255.255.255.192 have 4 subnet

#

@tired root

valid garden
#

I have setup a django server, when I run python manage.py runserver I get: "Watching for file changes with StatReloader", and it seems stuck at this stage. when I do ctrl + c then I get performing systems check > starting development server etc.. but the server is not up

tired root
#

@white pewter That subnet can contain 62 hosts, the max number is 255, so 255.255.255.192 can contain 4 networks

white pewter
#

How did u know 62 host it canhave

tired root
#

Because 256/64 is 4

white pewter
#

What

#

Oh

tired root
#

Remember, 62 hosts, + 1 ID + 1 Broadcast = 64

white pewter
#

Ok

#

I was reading this

tired root
#

255.255.255.192 are 26 bits

#

255.255.255 = 24

#

192 = 128 + 64 = 2 bits

#

Because bits order is 128 64 32 16 8 4 2 1

white pewter
#

Fucking bits

tired root
#

it all comes down to the bitwise addition

white pewter
#

Fuck binary

tired root
#

TO subnet, you are splitting a number in half

#

Basically

#

so you need to go down to the bit level

white pewter
#

Ok

tired root
#

Take a piece of paper, make a table with the bits

#

Then insert your desired netmask into it

#

calculate the number

#

Once you get the hang of that, you'll be subnetting without even doing math

white pewter
#

@tired root finally learnt

#

How to change cidr to subnet mask

tired root
#

It's the same

white pewter
#

Then use subnet mask for determining net id

tired root
#

255.255.255.0 is 24 bits

#

so cidr notation is /24

white pewter
#

Yes i had confusion in Cidr and submet mask but now i m not

#

I feel easy

#

Also i learnt how to determine net id from cidr

tired root
#

Net ID is always the first ip in the subnet

#

broadcast last

white pewter
#

I dont know what is broadcast or broadcast id

tired root
#

Broadcast is the last IP in the subnet

#

That is really all it is

#

What it is for is irrelevant for now

#

So, got a net with 192.168.0.0/16

#

ID is 192.168.0.0

#

Broadcast is 192.168.255.255

white pewter
#

Good

#

Thanks

#

Bye

#

I m relieved

#

After 4 hrs now i. Understand

white pewter
#

@patent cobalt why cant i talk in offtopic

patent cobalt
white pewter
#

There are lot of announcement which in particular to see?

#

@patent cobalt

#

I mean like 100s of them

patent cobalt
#

The very last one

white pewter
#

Ok

#

So i cant talk because of covid 19

#

Do they spead from discord

#

@patent cobalt

patent cobalt
#

You'll need to confirm you've washed your hands in #bot-commands and you'll be able to talk in off-topic

white pewter
#

Oh

#

Those bot commands

nimble epoch
#

A question about Django

#

What is {{ forloop.counter }}

#

?

supple loom
#

Anyone uses FastApi can tell me if we need to use both pydantic models and SQLAlchemy models or only one of them?

feral minnow
#

Guys i wanna upload a youtube downloader to a server to be hosted on the web how i can create folder in that server and download files?

heady ore
#

Hi, I want to ask why I got the 'refused to connect' message on web? I'm using django and I've set with 'xframe_options_exempt'. I can view the file with

<p>Open a PDF file <a href= {{ content.file.url }} >example</a>.</p>

after click the button. but not able to view directly with

<iframe id="iframepdf" src= {{ content.file.url }} width="100%" height="500px"></iframe>

Do I have any wrong setting? Thanks

native tide
gilded dragon
#

It looks like it's not properly finding an associated view or URL path, maybe

native tide
#

@gilded dragon yep but I'm not getting it can you help?

gilded dragon
#

No, I am not good enough at Django yet to help you adequately. I'm just helping how I can. It looks like the URL you're requesting is kind of... Weird? Maybe check out what's going on there? It's possible the link you're requesting from your server is not in your urlconfs so maybe fix that or see if it's correct

tired root
#

@native tide %5E is ^ , so there is somewhere an extranious ^ in your code

gilded dragon
#

Probably in the http request he's making, yes?

tired root
#

in the url...

gilded dragon
#

Right, I know

#

But where would that ^ be, code-wise? In the request he's putting to the server, yes? He's "asking" to go to ^Like/$ somewhere

native tide
#

this is url path ```
path(r'^like/$', views.like_post, name='like_post'),

tired root
#

there you go

#

there is your ^

gilded dragon
#

Theres your problem

native tide
tired root
#

The ^ is still in your url

gilded dragon
#

Yep

tired root
#

do you not see that your url is malformed?

native tide
#

how do I solve it?

gilded dragon
#

Also media has a ^ in it too, not sure what that's about but you might want to fix it now or resolve why it's there in the first place

#

The thing you're requesting with is asking for a url with ^ in it

native tide
#

I remove ^ but it didn't work

gilded dragon
#

Perhaps a button?

#

Remove the ^ from the request that the button or whatever it is you're trying to send to the server

tired root
#

I wonder why you are trying to regex a url anyway?

#

An Url is not a suggestion, it is hardcoded

gilded dragon
#

Oh he's REGEXING

#

I was like... Why the fuck is there a ^ in that?

tired root
#

@gilded dragon The running commentary is really not necessary

native tide
#

I'm trying to make a like button Its working but whenever I press it it give this error working means I can see likes in admin page

tired root
#

ok, but why the ^like/$ as if you are regexing it?

#

Just do /like/postid/ done

#

Or the id of whatever is getting liked

#

Anyway, your issue is that the url is malformed due to the ^ and I don't see your code, so you gotta somehow fix that. Your routes seem to have a /like/ path, maybe adjust to what I suggested or simple remove the ^ and figure it out from there

meager glen
#

Hi, how can i download a file to a flask server?
I would like to download an online video to the flask webserver then send it to the user. Ik know how to send the file just not how to download it specifically to the sever.

tired root
#

Use a request

native tide
#

It didn't work dude

tired root
#

You didn't what?

native tide
#

oop

tired root
#

ok, we don't help with that

#

That violates YT's terms of service

#

so good luck

native tide
#

look at this ```
Page not found (404)
Request Method: POST
Request URL: http://127.0.0.1:8000/like/postid
Using the URLconf defined in django_project.urls, Django tried these URL patterns, in this order:

admin/
register/ [name='register']
profile/ [name='profile']
login/ [name='login']
logout/ [name='logout']
password-reset/ [name='password_reset']
password-rest/done/ [name='password_reset_done']
password-reset-confirm/<uidb64>/<token> [name='password_reset_confirm']
password-reset-complete/ [name='password_reset_complete']
[name='blog-home']
user/str:username [name='user-posts']
post/int:pk/ [name='post-detail']
post/new/ [name='post-create']
post/int:pk/update/ [name='post-update']
post/int:pk/delete/ [name='post-delete']
announcements/ [name='blog-announcements']
about/ [name='blog-about']
^like/$ [name='like_post'] #This line here
^media/(?P<path>.*)$

tired root
#

ok, but now the ^ is gone from the url, so thats good

#

postid was actually a sample variable to denote the id of whatever post or image you want to be liked

#

it wasn't literally

#

I was a suggestion how to structure this

native tide
#

ik but I tried it cuz I'm pissed off and nothing is in my mind

tired root
#

The route would be something like /like/<int:postid>

#

Then use that post id in your code to increase the like count

#

however you do that in your project

feral minnow
#

Anyone using heroku here

#

?

vagrant adder
#

ye

feral minnow
#

what i have to put in the Procfile file?

#

Im using python

#

flask

#

@vagrant adder

vagrant adder
#

are you using gunicorn

#

and what does your project structure look like?

feral minnow
#

hm?

vagrant adder
#

it is recommended to use proper web server in production, not python app.py

feral minnow
#

oh

vagrant adder
#

and what does your project tree look like?

feral minnow
#

the flask one

#

but html

#

in templates

#

I will screenshot

#

1s

vagrant adder
#

where do you app.run() ?

feral minnow
#

yup

vagrant adder
#

okay

#

first, install gunicorn

#

pip install gunicorn

#

and put it in your requirements.txt

feral minnow
#

install it on my pc?

vagrant adder
#

yes

#

pip install gunicorn

feral minnow
#

Im downloading it

#

done

#

Procfile declares types -> (none)

#

I put it in requirements

#

@vagrant adder

tired root
#

And installing a web server on his personal computer will help him how to deploy his app on Heroku, @vagrant adder ?

#

I am very interested in that answer tbh

feral minnow
#

So...You know how to use the Procfile file??!

tired root
#

I don't use HEroku, so no

feral minnow
#

np

dusk zodiac
#

Ok... Hello Pips

#

Anyone with a clue on webscraping web app dev with Django?

feral minnow
#

hmm I don't if this will help but Im scraping youtube using flask

dusk zodiac
#

Go ahead... let me see if your tutorials can help

feral minnow
#

What are trying to scrape??

dusk zodiac
feral minnow
#

For me I made a youtube scraper first then I copied the code to flask and just modified it a little bit

native tide
feral minnow
#

check your code line 50

native tide
#

here is the view where its taking error from ```
class PostDetailView(DetailView):
model = Post

def like_post(request):
post = get_object_or_404(Post, id=request.POST['post_id'])
post.likes.add(request.user) #This one is line 50
return HttpResponseRedirect(post.get_absolute_url())

feral minnow
#

make sure you write it in the right way

#

maybe post_like or post_likes

#

I don't anything about django but maybe this will work

native tide
#

this is the url path So ...

    path(r'like/', views.like_post, name='like_post'),
``` like_post maybe?
feral minnow
#

try it

#

what are you trying to do btw?

native tide
#

I'm trying to make a like button for my blog site

feral minnow
#

oh

#

maybe this will help

native tide
#

okay lemme check

feral minnow
#

did you fix it @native tide ?

native tide
#

yep I fixed it but I got new issue

#

I changed some stuff in views.py and it worked but when I set @login_required and when the user login It gives error
to avoid that I need to change it to previous page so how can I refer him to previous page? @feral minnow

feral minnow
#

is there something called redirect or something like that in django?

native tide
#

yeah I think its href you're talking about

feral minnow
#

not html

native tide
#

actually djengo is just backend the main thing is html

feral minnow
#

scroll down

#

you will find something called redirect

native tide
#

@feral minnow yep I've absolute.url() already

feral minnow
#

screenshot you code pls

native tide
feral minnow
#

where you want to redirect the user?

#

to which function I mean

native tide
#

to the post detail page

vagrant adder
#

okay so lion

native tide
#

wait I figured

vagrant adder
#

do you have gunicorn installed

feral minnow
#

yup

#

How I can check?

vagrant adder
#

can you do gunicorn main:app in terminal?

feral minnow
#

my pc cmd?

vagrant adder
#

yes

feral minnow
#

something showed up on the screen

#

brb 5m

native tide
feral minnow
#

back

#

@native tide dose it save the things that the user enter ?

#

@vagrant adder I run it

#

ModuleNotFoundError: No module named 'fcntl'

#

@native tide try return redirect('the function you want')

native tide
#

oop I messed up again this function shows the like button only for post author

feral minnow
#

@vagrant adder

thorn bloom
#

Hello everyone, i am new here, not to python(covered till oops) but new to django, what would you recommend the best resource to learn Django for a beginner??

tired root
#

A flask tutorial 😛

vagrant adder
#

@feral minnow install fcntl then

feral minnow
#

It give an error

#

when i try to install it

#

@vagrant adder I put my files on github and connected it to heruko

#

Why I have to install it in my device ??

vagrant adder
#

you don't have to install it on your system, you only have to have it specified in requirements.txt

feral minnow
#

I put it

#

@vagrant adder

vagrant adder
#

okay, do you have procfile

foggy narwhal
#

Hi all, and thanks for the help in advance. I'm facing an issue with Flask and I would really appreciate the thelp.

Just le me know when someonse is free so i dont clutter the channel.
Thanks and sorry for my English (im from Argentina and spanish is my native tongue)

feral minnow
#

yes

#

what I have to put in it?

#

its not working

vagrant adder
#

you can just do web: gunicorn main:app

feral minnow
#

its a 237 line

#

if you want I can share screen in help voice-chat

vagrant adder
#

you can use hasebin or something

feral minnow
#

1s

foggy narwhal
#

@vagrant adder can I borrow 5 min from you once you are finished with @feral minnow ?

vagrant adder
#

sure thing

vagrant adder
#

you need something?

foggy narwhal
#

Essentially Im practicing while creating a team builder based on players attack and defense stats; and the return_template call is not being passed when I post to the /teams form

`
from flask import Flask, render_template, request
import csv
import random

app = Flask(name)
app.config["DEBUG"] = True

file = "XXXXXXX"
allPlayersData = []
with open(file, 'r') as data:
csv_data = csv.DictReader(data)
for row in csv_data:
allPlayersData.append(dict(row))

shownPlayers = []
for item in allPlayersData:
shownPlayers.append(item['name'])

print(shownPlayers)

def searchPlayer(name):
for p in allPlayersData:
if p['name'] == name:
return p

def buildTeams(playersList):
selectedPlayers = []
for item in playersList:
playerData = searchPlayer(item)
selectedPlayers.append(playerData)
teamAtkDelta = 4
teamDefDelta = 4
team1 = []
team2 = []
while teamAtkDelta >= 4 or teamDefDelta >= 4:
sampling = random.sample(selectedPlayers, 16)
team1 = sampling[0:8]
team2 = sampling[8:16]
team1Defense = sum(int(item['defense']) for item in team1)
team1Attack = sum(int(item['attack']) for item in team1)
team2Defense = sum(int(item['defense']) for item in team2)
team2Attack = sum(int(item['attack']) for item in team2)
teamDefDelta = abs(team1Defense - team2Defense)
teamAtkDelta = abs(team1Attack - team2Attack)
return render_template('teams.html', team1 = team1, team2 = team2)

@app.route('/', methods=['GET', 'POST'])
def availablePlayers():
return render_template('players.html', shownPlayers = shownPlayers)

@app.route('/teams', methods=['POST'])
def buildDamnTeams():
selectedPlayers = request.form.getlist('selectedPlayers')
if len(selectedPlayers) >= 16:
buildTeams(selectedPlayers)
else:
return "missing players, should be 16"
`

#

everyhing is working fine except that call to buildTeams() on the /teams call on POST

#

TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.

vagrant adder
#

it does that when you select 16 or more players?

foggy narwhal
#

correct, when you select at least 16

vagrant adder
#

okay i found a problem

foggy narwhal
#

been reading and probably has somehing to do that the render_template should always have app context

#

could that be the issue?

vagrant adder
#

so when you select at least 16, you call function but never return anything from route functions

foggy narwhal
#

but the buildTeam function returns render_template and stuff, right?

vagrant adder
#

your buildTeams returns already rendered html and such, but it returns to route level, not outside it

#

i would do like this:

  • make that buildTime only returns teams
#

so it ends in return [team1, team2]

#

and in your route:

if len(selectedPlayers) >= 16:
    team1, team2 = buildTeams(selectedPlayers)
    return render_template("teams.html", team1=team1, team2=team2)
else:
    return "missing players, should be 16" 
foggy narwhal
#

cool, 2 min while ill make those adjustments

#

you are the man!

#

thank you!

vagrant adder
#

cheers man

tired root
#

Again, we don't help with things like that

nimble epoch
#

@feral minnow, @tired root is angry again i think he didn’t have enough sleep

#

Just Don’t notice

tired root
#

@nimble epoch That has nothing to with angry, we do not help with violations of TOS

#

<@&267629731250176001>

feral minnow
#

This will finish it

kind steppe
#

scorcher is right, we won't assist with that.

#

@nimble epoch don't be sarky like that

feral minnow
#

oh okay

kind steppe
#

hold on

#

what are you downloading the mp3s from?

feral minnow
#

youtube

kind steppe
#

Yeah, the YouTube ToS forbids that

#

!ytdl

lavish prismBOT
#

Per PyDis' Rule 5, we are unable to assist with questions related to youtube-dl, commonly used by Discord bots to stream audio, as its use violates YouTube's Terms of Service.

For reference, this usage is covered by the following clauses in YouTube's TOS, as of 2019-07-22:

The following restrictions apply to your use of the Service. You are not allowed to:  

1. access, reproduce, download, distribute, transmit, broadcast, display, sell, license, alter, modify or otherwise use any part of the Service or any Content except: (a) as specifically permitted by the Service;  (b) with prior written permission from YouTube and, if applicable, the respective rights holders; or (c) as permitted by applicable law;  

3. access the Service using any automated means (such as robots, botnets or scrapers) except: (a) in the case of public search engines, in accordance with YouTube’s robots.txt file; (b) with YouTube’s prior written permission; or (c) as permitted by applicable law;  

9. use the Service to view or listen to Content other than for personal, non-commercial use (for example, you may not publicly screen videos or stream music from the Service)
feral minnow
#

Is this for pytube too?

kind steppe
#

yes

tired root
#

It's the act of downloading, not the script you use

kind steppe
#

any service which pulls content from youtube not using the official API

#

(the official API does not have that capability either)

feral minnow
#

oh

#

Okay thx

#

I will delete my question up their then

kind steppe
#

Thank you

feral minnow
#

Wlc

nimble epoch
#

I didnt know

#

Wow🧐🥵😳

kindred glacier
#

Does anyone know the answer to this question?

feral minnow
#

oh

#

1s

#

Watch this video I think it will answer the question

#

@kindred glacier

kindred glacier
#

@feral minnow I'm using sqlite

feral minnow
#

oh

simple escarp
#

you can use sqlalchemy with sqlite

little steppe
#

Is there some fundamental difference between serving a static image, and using send_file() to return an image?

Ideally I would not like to store a bunch of static images, but generate them dynamically on the fly (specifically using this: https://github.com/kebu/py-avataaars, combining a few svgs to render a png). I've set up an endpoint to send_file(image_bytes, mimetype), and it appears its working as expected when testing in a browser, but for some reason a mobile sdk that I am using it doesn't understand the image format.

If I curl my same endpoint to download an image, and serve that as a static file the mobile sdk understands the image as expected.

I feel like I am missing out on a tiny detail. Ideally I would prefer not having to generate some static file for every combination of avatar (very large amount), but generate them as needed.

quasi ridge
#

sounds like one of the response headers differs

#

see what headers your server sends in both cases: send_file, and static file

little steppe
#

gonna try that now, thanks for the response!

#

looks like the content-length isn't being sent with send_file() since I'm not passing a filename, time to do some digging

little steppe
#

hmmm, it appears extending a flask restplus Resource for the endpoint was somehow causing problems. I attached the endpoint directly to the app instead of extending a Resource and it looks like its working now, thanks again

quasi ridge
#

💐

quasi path
#

I have made this website with backend as node. I want to shift to a python web farmework and show analytics using Scipy. Any suggestions for how should I go ahead. Regarding choosing a famework ...
http://covid19.vshsolutions.com/

supple loom
#

Anyone knows about FastApi and how to update data in it ?

turbid glen
#
div{
    width: 50px;
    height: 50px;
    background-color: lightcoral;
    line-height: 50px;
    text-align: center;
    animation: move 2s infinite alternate linear, change 2s infinite alternate linear;
}
@keyframes change{
    0%{transform: rotate(0deg);}
    100%{transform: rotate(90deg);}
}
@keyframes move{
    0%{transform:translate(0px,0px);}
    100%{transform:translate(100px,100px);}
}
#

anyone know why these 2 animation arent working at the same time

tired root
#

@turbid glen Because you can only apply one animation to one element at a time with css

turbid glen
#

but if i change the @keyframe move to 0% background-color red to 100% bg color green it works

#

both of them work at the same time, i mean

tired root
#

make a fiddle of that because that'd be unusual that it suddenly works when changing the color

turbid glen
tired root
#

Still doesn't move in chrome

turbid glen
#

yea

tired root
#

Also does not work in Firefox

turbid glen
#

but why doenst it move when its translate?

#

the background color works tho

tired root
#

Because you can only apply one transform at a time

#

And if you do it at once,the result would be moving in an angle

#

Because the matrix didn't get reset between

turbid glen
#

erm so can we write like this transform: rotate(xx), translate(xx,xx)

#

combine them together

tired root
#

As I said, it would be moving in an angle

#

If you'd do something like this in a game, you'd need to reset the modelview matrix in between rotation and translation

#

The same principle applies here

#

BUt you can't do that, and which is why I said only one animation per element

#

the background-color isn't such an animation

turbid glen
#

ok then

tired root
#

it's a simple property

turbid glen
#

ty

toxic marten
#

Im working with Flask, and i discovered (with miguel grimberg course) that there is a dedicated extension for bootstrap (pip install flask-bootstrap). This extension will add some bootstrap folder and files in templates folder. But the problem is that i can use only bootstrap 3, because the extension is based on this version. Instead i want to use bootstrap 4. I found another extension (pip install Flask-Bootstrap4), but it doesn't create any folder, files, etc in templates files. It should add some files used by the extension, but it doesn't. I dont understand

#

Does someone use bootstrap 4 with flask? If yes, can you explain me a little bit, in general, how bootstrap and flask work together

vagrant adder
#

you can just import it through cdn in your templates

#

and it will work just fine

toxic marten
#

Yes, ive done that, the problem is that flask-bootstrap extension has some features (macros) that are stored in some files. But there no files

vagrant adder
#

flask has templating engine that interacts with templates

#

flask bootstrap interacts with templating engine to give you more css (in a nutshell)

toxic marten
#

Yes. But im not referring to that. Flask-bootstrap has some features (macros), for example render_field(), render_form(), render_nav_item(), etc that are stored in bootstrap/form.html

#

But there no files. Theres no bootstrap folder. The problem is this

#

However i dont understand at first if flask-bootstrap is the version 3 or 4 of bootstrap. Documentation says that is version 3. A lot of tutorial says that is version 3, because all of this tutorial are old (most are old 3 years ago or more). But now for example i found this doc that says it is bootstrap version 4. Im really confused

lavish prismBOT
#

Hey @toxic marten!

It looks like you tried to attach file type(s) that we do not allow (.pdf). We currently allow the following file types: .3gp, .3g2, .avi, .bmp, .gif, .h264, .jpg, .jpeg, .m4v, .mkv, .mov, .mp4, .mpeg, .mpg, .png, .tiff, .wmv, .svg, .psd, .ai, .aep, .xcf, .mp3, .wav, .ogg, .md.

Feel free to ask in #community-meta if you think this is a mistake.

toxic marten
cunning prairie
#

I am looking in Django for an elegant way to destroy all user related active sessions. Preferably maybe I overlooked to do it in Django way? Currently I am using password_change from django.contrib.auth to change password and in addition after that I would like to destroy all the user sessions for security reason. I was shocked that Django default mechanism is not doing that.

topaz scarab
#

Hey, I'm trying to get into webautomation with python but I'm running into this problem where if I use the element of i.e a searchbox, and try to execute a method "send_keys" to it, the autocompletion doesn't register that for me.

The weird thing is that there are 0 error pop ups after I - manually - write out the whole command. However, it consistently executes a "element not interactable" error when I try to either click a button or send information.

When I try to instead use it as a script, it suddenly works fine and I can click on buttons as normal. Why does this happen?

cunning prairie
queen bough
#

@cunning prairie When change_password occurs successfully then call delete_all_unexpired_sessions_for_user. Should be that simple.

#

But, as I said, I've not done this before.

cunning prairie
#

In this case it seems that I would need to mess with django.contrib.auth.* files which I wanted to avoid. As I see password_change works pretty automatically, template is just {{ form.as_p }} and view with form comes from the lib

queen bough
#

Why would it mess with the contrib.auth files?

cunning prairie
#

How could I attach the code without modifying django.contrib.auth.* files?

#

To use password_change, I did only {% url 'password_change' %} in my html file, {{ form.as_p }} as template to render the form and path('account/', include('django.contrib.auth.urls')), to attach urls from the lib

#

that's all my code, I am not sure from where to execute delete_all_unexpired_sessions_for_user

queen bough
cunning prairie
#

I'll try to do it, thanks for a direction.

queen bough
cunning prairie
#

Yep, the following view class PasswordChangeView(PasswordContextMixin, FormView): I am trying to change

toxic marten
peak thicket
#

Is it possible to run aiohttp web servers asynchronously instead of blocking?

wide steppe
#

Can anyone experienced in github API v4 help me to define scopes for my app? I tried some combinations but every time it failed.

tired root
#

@peak thicket run it in a thread

peak thicket
#

Really?

#

That kinda sucks.

tired root
#

You can't run a main loop non blocking

#

The only solution for that is a thread

#

or having to do the loop yourself

peak thicket
#

Most asyncio applications have 2 ways of starting. 1 blocking method and an async method.

#

Like run() and await start().

#

Guess I'll just use Sanic or something.

sick niche
#

Is there some reason requests.get() wouldn't add parameters to my url? I'm trying to get a response but it's like my parameters are just ignored:

import requests

placeId = 286090429

url = "http://roblox.com/Games/GetGamePassesInnerPartial"
params = {
    "startIndex" : 0,
    "maxRows": 50,
    "placeId": placeId
}

data = requests.get(url, params=params)
print(data.url) 

# Ouput: https://www.roblox.com/Games/GetGamePassesInnerPartial 
# Expected output: http://roblox.com/Games/GetGamePassesInnerPartial?startIndex=0&maxRows=10&placeId=286090429
tired root
#

Okay

#

just tried this

#

and it works for me

sick niche
#

Huh

tired root
sick niche
#

Wow

tired root
#

My initial thought was that url is only the base url, but I was obviously wrong there

sick niche
#

I though the IDE might not be updating the script but my script is observing changes correctly

#

Running the script directly through cmd line outputs the same thing

feral minnow
#

Hey guys anyone know how download files to heroku servers?

tired root
#

...

feral minnow
#

I didn't say "youtube files"

tired root
#

A download is the same thing as downloading a web page

#

it is a http request

#

so use request from flask or the requests package from Python

#

pip install requests

#

then do a get request on the file you want

#

If Heroku allows that, idk, I don't use that service

feral minnow
#

oh

#

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

#

Dose that mean that heroku doesn't allow to download files?

tired root
#

How can we tell without context?

feral minnow
#

1s

gilded dragon
#

Django question real quick. Setting up a simple website/webserver. Should my apps be initiated in the same directory as my "base" project files (so like, settings.py, wsgi.py, etc.) or above a directory, where manage.py is? I'm still kind of confused on that.

tired root
#

apps initiated? what?

gilded dragon
#

Like when you start an app.

tired root
#

You don't start an app

gilded dragon
#

It creates the directory with the app's files.

tired root
#

The webserver runs the python code

gilded dragon
#

The command is "startapp". So what else do you want me to call it?

#

When an app is first created, I'm trying to figure out where in the directory hierarchy it should be created/initiated in.

#

Right now, I have it in the same directory as my "base project app", or whatever that's called. So the new app's directory is in the same directory as the base app, and manage.py.

tired root
#

from the same directory

#

On a webserver, things are different

gilded dragon
#

I don't think that's relevant to the question

tired root
#

ok then

gilded dragon
#

I'm just looking to get my directory hierarchy set up correctly right now

tired root
#

You said you are looking to setup a web server. Excuse me for giving you an answer to what you are asking 😦

gilded dragon
#

I appreciate what you told me, but I need to get square 1 figured out first my dude

#

So, if you are willing, can you tell me if my directory hierarchy looks acceptable for ensuring that my apps are where they belong? I just want to get this right early on, so that it doesn't cause problems later.

shadow orchid
#

Hey wanna get started with flask!, to creata a webhook!

#

Any docs to get me started

rustic pebble
#

@shadow orchid discord webhook?

shadow orchid
#

nope

#

whatsapp chatbot

#

tiwlo api

#

need a webhook

#

twilio

meager glen
#

Is it possible to download an image off the web to like a web server, ex: heroku?

dusk zodiac
#

Hello guys

#

Anyone knows a library to webscrap js webpages?

hollow cave
#

@dusk zodiac maybe dryscape?

#

Anyone have good tutorials or advice for getting up to speed on a Flask/Graphene/Postgres/SQLAlchemy web app? I'm confused on how everything is working together (Front end is REACT, graphql)

high panther
#

I've been using flask for all of my webapi purposes but I've had a chance to take a more detailed look at aiohttp, I've made the move from requests to aiohttp to stop thread blocking and saw it also has several server functions, would I be better off moving my api to aiohttp over flask?

#

for context, better in terms of speed and ease of use from my POV

#

namely writing code for streaming content

oblique hemlock
#

Hello

#

I wanna return a wav file using flask

#

Any ideas?

#

It's an external file in the system btw

#

I tried send_file but It actually returned an invalid file :/

oblique hemlock
#

~

feral minnow
#

Hmm did you put the right path

#

For the file

errant spindle
#

hey guy

#

guys

kindred glacier
#

I have a simple web application that was built with flask and sqlite3. I have form, user can enter a name of grocery and quantity and it will get inserted into my database and on to list of grocery items. The problem I have is how to delete an item and how to implement this. I'm new to flask and having a hard to figuring this out

rustic pebble
#

Well deleting an item is probably equal to deleting a row

#

Model.query.filter_by(name=target_name).delete()

#

Model is your db model, target_name and name are just place holders they can be whatever the columns you have are and delete is self-explained

static night
#

I created new Django project with PyCharm how I can login now into Admin?

toxic marten
#

Does someone use flask-wtf or flask-bootstrap?

tired root
#

@toxic marten No to flask-wtf, because writing my forms is faster in HTML than that library. No to flask-bootstrap, because I am not going to burden my users with megabytes of code for something I can do by hand.

toxic marten
#

Ok ok. I just only want to ask about csrf protection

#

Without flask-wtf, how can i do this protection?

tired root
#
import uuid
def generate_random_string():
    return str(uuid.uuid4())
#

That is one way

#

but just read up on it, explaining the whole process is too much for a chat

#

one important thing: Always use POST, never anything else

#

Also make sure your site is protected against XSS attacks

#

Thinking about it, you could also generate a session secret and encrypt the random string with that

#

So you can decrypt it when it comes back and make sure it is legit

toxic marten
#

Thank you

orchid current
#

I really need help with memcache 😦

#

Can someone who has the time and the patience and the courage pm me to mentor me on how to use caching with the Flask app that I'm coding? Tyvm in advance!

tired root
#

WE are not doing dm help

#

And I am giving you this free warning: open memcache servers are dangerous

#

make sure you know what you are doing

orchid current
#

@tired root thanks and I'm sorry for the wrongdoing on my part!

toxic marten
#

How can i disable browser default alert? Here there are at the same moment, the chrome alert and my custom alert that inform the user that must fill the form (im working backend side)

native tide
#

remove the required property

#

@toxic marten

toxic marten
#

I didnt use required property, but it is rendered in the page because i use DateRequired()

#
    name = StringField('Username', [DataRequired()])
    email = StringField('Email', [DataRequired(), Email()])
    submit = SubmitField('Submit')```
fair linden
#

Does anyone know how to get the Recaptcha from a website, solve it somewhere else, then use post the solution in the original website
Like how 2Captcha and anti-Captcha work

magic blade
#

Django models question -- i've got a model (Cart, as in shopping) which has a ManyToManyField to a Product, using a CartItem as the intermediary model. in the process of building a feature, I've discovered there are some number of Cart instances whose ManyToManyField appears empty (i.e., no relations to Product instances), but for whom cart.cartitem_set (the intermediary relation) is not empty. Trying to decide how much to care about this before digging into how that happened and whether it needs to be fixed...

kindred glacier
#

@rustic pebble I don't understand how I can implement it to my HTML

rustic pebble
#

You will do that on the server-side of things. usually that means app.py

kindred glacier
#

@rustic pebble The way I add an item is I use request.form['form_name'] and add that to the sql query placeholder.

#

but not sure how to do that with delete

#

How does my app know which item I want to delete?

rustic pebble
#

You need to create a model

#

After that you can use an identifier, it can be w/e u want to be able to choose what row you want to deelte

cosmic lantern
#

Does Flask have a way to save a session ID in the client?

native tide
#

@toxic marten the pop up is an HTML5 feature you added a DataRequired() validator to you form which adds the required field

#

@cosmic lantern yes flask can manage sessions. in the session variable or you can use flask-session and let it handle the sessions for you

cosmic lantern
#

oh, so flask-session just simplifies this?

toxic marten
#

@toxic marten the pop up is an HTML5 feature you added a DataRequired() validator to you form which adds the required field
@native tide Ok thank you @native tide . So i dont have to use required

#

But how can i implement the feature that input must be filled

native tide
#

yes flask-sessions is built on top of the session it makes it easier to manage user sessions the docs are also pretty good

toxic marten
#

If i dont use DataRequired(), will i use a rules created by me?

cosmic lantern
#

Do I understand it right, that sessions can store a session ID which can be used to authenticate API calls, so that the user doesn't have to log in again every time they visit my site?

native tide
#

@toxic marten if your field is required then add DataRequired

#

@cosmic lantern the session is a dictionary that has a csrf token added to it by the flask api apart from that you can pretty much add anything you want. user settings/ username etc

cosmic lantern
#

well I have a DB on the server that stores that SessionID along with a user ID that identifies a user. The client should only have that session ID and sends that along with a request every time it contacts the server

native tide
#

but i highly recommend using Flask-session coz you can get current user by defining a user schema that the Flask-session can use

#

so youre generating a sessionID for the user yourself?

cosmic lantern
#

can I store the corresponding user ID in Flask-Session?

#

no, currently not as I haven't implemented that yet

#

but I plan to

native tide
#

yes you can store it in the flasksession

cosmic lantern
#

since I want, as i said, to store a corresponding user ID for that session ID in my DB

#

okay

native tide
#

you can store and entire user object in the session

toxic marten
#

@native tide the problem is that i want that user must fill the input, but i dont want to use the default browser alert, generated by required. So, if use DateRequired(), it will render with required feature. I want to create a custom alert, for example the bootstrap alert that inform users to fill to fill the form. But if i dont use required and DateRequired(), what should i do?

#

Sorry for my bad english

cosmic lantern
#

flask session doesn't seem very popular 🤔

toxic marten
native tide
#

@toxic marten yes you can add that too

cosmic lantern
#

but what are the advantages of using flask session if I am storing the session ID in my db anyways?

native tide
#

but if you submit a form without any data in it the required alert will pop up

#

@cosmic lantern then you dont have to waste time querying the DB

#

the session object also persists which means once the user closes the browser and logs back in you dont have to redirect them to the login page.

cosmic lantern
toxic marten
#

Oops, i dont mean alert, i say a bullshit. I mean valid-feedback and invalid-feedback classes

native tide
toxic marten
#

@toxic marten yes you can add that too
@native tide Yes ok. But i dont understand, sorry its first time that i try custom required

cosmic lantern
#

okay, thanks!

native tide
#

@toxic marten the required attribute basically prevents you from submitting an empty form

toxic marten
#

Yes i understood that

#

Im not very good with english, so maybe i dont ask you the question very well

#

But the problem is:

#

I want that user fill the input, BUT i dont want to render default browser alert, instead i want to do something like with bootstrap, i mean a text under the the input that says if input is ok or not. But if i cant use required and DataRequired(), how can i say to flask that the form must be filled. Because if i cant use DateRequired() what should i use?

#

@native tide I tried to write the best possible in English

native tide
#

you should use DataRequired(). once the user has submitted the form you should check if the form is valid by calling form.validate_on_submit()

#

then if there are any errors you can then send the form object to the template where you render your custom error

cosmic lantern
#

well, what should I use as the session ID? is it fine to just use a randomly generated string?

native tide
#

whats the users primary key?

cosmic lantern
#

it's a user ID (also the _id of the user in my mongodb DB)

#

or what do you mean by "key"?

native tide
#

the _id should be fine

cosmic lantern
#

but I shouldn't just store the password and the username in the session, should i?