#web-development

2 messages ยท Page 90 of 1

open forum
#

@solemn topaz We do not allow recruitment on this server, sorry.

tepid stirrup
#

Hi all

DATETIMES and TIMEZONES. What the hell.

I am building a chat feature into a website and currently all of the users are on one timezone but if it starts getting users from a different timezone will that mess up the time stamps of the message if the time stamps are timezone naive?
Wondering if the solution would be to have timestamp timezone as UTC and then asking the user to give their timezone to do the conversion. Help please ๐Ÿ˜‚

zealous siren
#

most systems store time in UTC then convert

tepid stirrup
#

@zealous siren Thanks so I will have to get timezones from the user

zealous siren
#

I believe you can with Javascript

tepid stirrup
#

Aw okay thanks for that. I will look into it.

sly canyon
#

@tepid stirrup I'd go with datetime.utcnow() to register everything. you can format times according to the user's location using other tools.

#

moment.js, pendulum, ....

vale orbit
#

are there any good python library for manipulating the DOM, or do I have to use javascript for that?

#

I'm trying to figure out just how full-stack I can get with Python

zealous siren
#

if you are trying to make a modern site, backend only with python

#

Frontend will be mostly to all JS/TS

vale orbit
#

.....well fuck

sly canyon
#

@vale orbit I feel the same

vale orbit
#

Guess I cannot put off learning JS any longer then

sly canyon
#

Python on web front-end ASAP

#

I almost hate JS

vale orbit
#

from what I understand, TS isn't nearly as cancerous as JS, so I guess there's that?

sly canyon
#

but it's an evil we have to deal with

vale orbit
#

I hate JS, but not nearly as much as I hate Java

sly canyon
#

never tried, probably never will.

vale orbit
#

remember when Java was all about making OOP faster and more effective?

I remember. It has been a long time since then.

#

but I digress

zealous siren
#

it did when it came out

tepid stirrup
#

@sly canyon Thanks! How does that work with dates and times set by the user just for future ref

sly canyon
#

JS has nothing to do with Java, thankfully

zealous siren
#

but like many legacy stuff, it aged poorly

sly canyon
#

EC6 was just trying to make a name that would catch

vale orbit
#

It was rushed.

#

They were like "we need to get this language out now, even if it barely works"

zealous siren
#

yea, but getting offtopic, point is, good frontends will be Javascript frontends

#

look into React/Vue/Angular

vale orbit
#

Ok, so over-under on Svelte JS?

sly canyon
#

@tepid stirrup you can request.remote_addr and do some GeoIP to guess their location/timezone

zealous siren
#

edug, that's just delaying doing proper thing

tepid stirrup
#

@sly canyon What I mean is like if they wanted to make a start and end time for a task but it was a planner or something like that.

sly canyon
tepid stirrup
white tree
#

re: Flask routing - is there anything inherently wrong with combining get and post endpoints in the same entry, or should I create an @app.route() for each?

sly canyon
#

nothing wrong in my POV, sometimes even necessary for me to avoid argparsing

white tree
#

@sly canyon could I perhaps have you take a look at my example and get your feedback on why it might be causing a 500 error?

sly canyon
#

but if there's too much code and you can split them up, I'd do that

white tree
#

just a tic

#

both get and post return 500, and nothing of any use is getting logged

sly canyon
#

you don't need if request.method == 'GET': 'cause thats the default behavior

white tree
#

oh. I wasn't sure how to differentiate - guess I should've read the docs more thoroughly, haha.

#

that said - it does work... most of the time.

#

but for reasons I can't quite figure (which is why Im here) after a while, it stops working and just returns 500.

sly canyon
#

I'm really not sure why that is

white tree
#

the logs only show WSGI errors with the queries being executed

sly canyon
#

maybe something related to your databse

white tree
#

well, I thought the same at first two. its just a standard local only mysql. but when I mysql console, it executes queries just fine.

#

I was however curious about the request object. perhaps Im expecting the wrong behavior from it?

sly canyon
#

does the internal error happens on local env or only in production?~~~~

white tree
#

its a personal project, so Ive just been tinkering with it on production (I know, bad form)

sly canyon
#

thatn that's probably why

#

you're expecting the production server to access stuff that are not there

#

your local db is not in the production server, most probably

white tree
#

oh no, Im sorry

sly canyon
#

as soon as you query something, it fails to find it

white tree
#

when I say local only - I meant - closed off from external connection. it's "local" to the app.

#

thats my mistake.

sly canyon
#

so you're seeing internal server error on localhost?

white tree
#

yessir

sly canyon
#

what does the debugger says

white tree
#

if I reset apache2, it goes away for a while

#

1 sec, I'll show you

sly canyon
#

yeah, really not sure

white tree
#

dang. well, thank you for your time in any case.

fickle fox
#

guys

#

i cant create db file for some reason

#
from flask_login import LoginManager, UserMixin, current_user
from flask_login import logout_user, login_required, login_user
import sqlite3
from flask_sqlalchemy import SQLAlchemy, request, Model


app = Flask(__name__)
app.config['SECRET_KEY'] ='ASSJHADCHASLFDLAKJKkjk;xsjd'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/users.db'
db = SQLAlchemy(app)


class User(db.Model):
    __bind_key__ = 'Users'
    uid = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(30), nullable=False)
    mail = db.Column(db.String(90), nullable=False)
    pw = db.Column(db.String(256), nullable=False)


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

this is code

#

:v

#

can anyone help?

warped timber
#

whats error?

#

also a: don't post your secret key b: that's an awful secret key, generate one using os.urandom or smth

#

@fickle fox

fickle fox
#

rn that is just for practice

#

@warped timber

vague ibex
#

is it possible to create a variable name using javascript based on an user input?

white tree
#

no.

proper hinge
#

Why would you need to do that?

#

That sounds like an xy problem

white tree
#

@proper hinge I get the meaning, but have never heard that expression. care to elaborate?

proper hinge
#

x is what they really want to do and y is how they want to do it, but y is not actually a good solution for x

#

So they should be asking how to do x, not how to do y.

#

i.e., the root of the problem

vague ibex
#

@proper hinge I have a problem. Can you help solve it?

#

I just the need the idea.. rest I can code

proper hinge
#

I'm not sure. What is the problem

vague ibex
#

So basically I have 5 setintervals. Now, I want to stop a particular interval and want to keep the rest running as normal. So, what should I do?

lethal orbit
#

Assign them to a variable?

#

What are the 5?

proper hinge
#

Use clearinterval to stop the one you need.

lethal orbit
#

Why does the name need to be user-defined?

vague ibex
#

yea that's a pretty cool solution. But the problem I am facing is : suppose 100 users set their setintervals. Now, I wanted to assign them to variables which would be suggested by the users to keep it more comfortable.

proper hinge
#

Why? Cause you need to be able to stop a specific user's interval?

vague ibex
#

yea!

proper hinge
#

If that's the case, store the interval ideas in a dictionary

#

And use the user's ID or something else to identify it

maiden kraken
#

Hello. I am having my Django project on github as private repository, but I posted some screen online about ideas for development and some guy askes sincere about checking my github code and giving me more specific advice. Is it safe to share my github code? I have all the files there, including settings.py and my sqlite3 database.

vague ibex
#

If that's the case, store the interval ideas in a dictionary
@proper hinge what do you mean by dictionary?

proper hinge
#

They're just called "objects" in JS I guess

#

A key-value mapping

#

A hashmap

lethal orbit
#

@maiden kraken does your settings.py contain Secret Keys and other private data?

vague ibex
#

yea objects are fine but still, is there not any more easy techniques?

proper hinge
#

I don't see how it could get any easier

lethal orbit
#

it is safe to share code if it is just code....

maiden kraken
#

Im afraid it does. What is the meaning of secret code anyway?

lethal orbit
#

(unless you have bugs you can exploit lol)

maiden kraken
lethal orbit
#

The proper way is to keep SECRET_KEY and database settings outside of your repo.

#

You should definitely never ever commit your database (unless it's for a test app).

vague ibex
#

@proper hinge So, you say that making objects will be better?

proper hinge
#

You can technically create variables with dynamic names, but this involves essentially modifying an object anyway, so it's a more hacky way of managing your own object. It's not really advantageous since presumably you'd need to dynamically retrieve those same variables too.

vague ibex
#

Can setinterval functions work while being inside an object?

proper hinge
#

Yes

#

The functions aren't inside an object

lethal orbit
#

Should I input new setting.py without secret code?
@maiden kraken you would have to change the secrets...

proper hinge
#

They just return an ID

#

and you're storing the ID in an object

lethal orbit
#

Once they are in git, you can easily see past commits.

vague ibex
#

so where am I storing the functions?

proper hinge
#

Functions don't get stored

#

They get called

lethal orbit
#

Just removing it won't scrub it.

vague ibex
#

I mean, How do i stop the intervals

#

a specific interval according to an user

proper hinge
#

By using the ID they return

#

setinterval returns an ID. If you pass that ID to clearinterval, it will stop it

vague ibex
#

oh man, I didn't even know that

maiden kraken
#

@lethal orbit yeah I know I messed up. It was hard for me since I learn git as well with this project. Anyway I think since this is just a side project for portfolio I can share it

vague ibex
#

How do I get that ID ?

proper hinge
#

Like I said, it's what the function returns

maiden kraken
#

@lethal orbit thanks for advice

lethal orbit
#

Do you have the website running in production @maiden kraken?

maiden kraken
#

no, I am still running it from local server, I use git as a private repo basically as a safe copy

vague ibex
#

Where do I store the ID and how do I interpret it?

lethal orbit
#

Well, if it is not running in production, sharing it won't shouldn't hurt ๐Ÿ™‚

maiden kraken
#

thanks a lot, you are not helping me the first time, I really appreciate your help ๐Ÿ™‚

proper hinge
#

Store the ID in an object

vague ibex
#

so a setinterval will have a specific ID Right and it wont change?

proper hinge
#

Make the user's name/ID the key, and the setinterval ID the value

#

Correct

vague ibex
#

how do i add it?

#

i mean

#

how is the value extracted?

proper hinge
#

Extracted from the object?

vague ibex
#

I mean when do i get the id

#

and where

proper hinge
#

It is returned by setinterval

#

I've noticed you have asked that a few times. Are you unfamiliar with how functions return things?

vague ibex
#

Yea

#

Haven't worked quite well with these things tbh. I've been focusing on deeper front end stuff (without deeper js)

#

@proper hinge What about I give the user the id to keep it with them? lol

#

Whenevr they want to force close the intrval, they can just enter the id

proper hinge
#
let id = window.setInterval(...)
window.clearInterval(id)
lethal orbit
#

@maiden kraken the proper way to do things:

# settings.py
SECRET_KEY = os.environ.get("DJANGO_SECRET_KEY")  # and save a key in en environment variable called DJANGO_SECRET_KEY
# do the same thing for Database Settings if you use postgres/mysql which require a username/pw

And add a .gitignore file:

# Database
sqlite.db
# Editor settings
.vscode
.idea
``` etc.
proper hinge
#

Basically that, except you need to store each id in an object to associate it with a certain user

vague ibex
#

cool

#

btw do all functions return id or only setintervals/settimeouts?

maiden kraken
#

@lethal orbit Thank a lot, my laziness is just biting me in the ass, I wanted to push forward with the code as far as I could and ignored... ignoring ๐Ÿ™‚ It's a lesson for the future

lethal orbit
#

All good. part of the learning process ๐Ÿ™‚

proper hinge
#

Each function returns something different, as functions are designed to perform different tasks. Some return nothing even. You'd need to read the documentation to know what each function returns.

lethal orbit
#

My decisions also always bite me in the ass months down the line lol

maiden kraken
#

yeah, might as well get use to it ๐Ÿ™‚

vague ibex
#

aight thanks friends! It really helped me1 ๐Ÿ˜„

lethal orbit
vague ibex
#

let a = setInterval(function(){console.log('a')},2000); let poke = { "o1" : setInterval(function(){console.log('a')},2000) };
clearInterval(poke.o1);

#

why did it not work?

#

the interval kept on repeating

lethal orbit
#

Don't you need a scope?

#
window.setInterval();
window.clearInterval();```
vague ibex
#

you mean the window?

lethal orbit
#

Yeah

#

let a = window.setInterval(...

vague ibex
#

yea ig you're right

#

thanks !!

coral raven
hallow jacinth
#

could someone help me figure out why flask bootstrap is not using grid even though i made the classes grid?

coral raven
#

Flask-bootstrap uses bootstrap v3 ig

#

@hallow jacinth

hallow jacinth
#

oh, so using the current documentation won't work :/

coral raven
#

Yup

hallow jacinth
#

I did not kno that it used v3, ty!

maiden kraken
#

Hi again, I am making a discussion board site. I have now login and logout functionality. How do I get username if the user is logged in and auto input it into a form so when the post is added it is added by this user?

#

def add_response(request): if request.user.is_authenticated: if request.method == 'POST': new_response_form = CreateResponseForm(data=request.POST) if new_response_form.is_valid(): new_topic = new_response_form.save(commit=False) new_topic.author = request.user.id new_topic.save() new_topic_form = CreateResponseForm() else: new_topic_form = CreateResponseForm()

marsh canyon
#

are u using the default User model?

maiden kraken
#

hmm yes, I also am extending default User with 1to1 relation but I think that is not changing much

marsh canyon
#

right

#

in ur code, u have got the user id by doing request.user.id, you can get the username in a similar way, request.user.username

maiden kraken
#

hmm, I think i don't really care if it is user id or name I think.. Problem is I get this:

#

NOT NULL constraint failed: homepage_forumresponse.author_id

#

and then

#

params

[None, '<p>test</p>', '2020-09-17 18:25:09.355271', 1]

#

first none is the author from what I assume

#

and it's None instead of name/id

#

yeah, from sql query I see that author is empty

maiden kraken
#

Okay, managed to solve it myself thanks

topaz widget
#

Hey does anyone know if there's any danger of SQL injection in simply using request.POST.get(...) to access POST body data from a form with Django?

#

I use the data from request.POST.get(...) in the constructor of an object that will be stored in the database, but I'm pretty sure it utilizes the ORM so I should be safe, right?

#

I don't write any SQL commands, just call the object's save method.

maiden kraken
#

@topaz widget im a beginner, but isn't csrf_token protecting you from this in any way?

topaz widget
#

@maiden kraken No, CSRF token protects against cross-site request forgeries, not SQL injection.

#

Very different method of attack.

#

@maiden kraken You should definitely read up on SQL injection, CSRF (cross-site request forgeries), and Cross-Site Scripting (XSS). They're probably the most common hacking methods / vulnerabilities for web applications and each require different practices to defend against.

hallow jacinth
#

anyone know an easy way to have a side nav in boostrap 3?

maiden kraken
#

@topaz widget Thanks a lot for the tip, I will definitely check that out before finishing my project

hallow jacinth
#

oh nvm found a link

topaz widget
#

@hallow jacinth Why are you not using bootstrap 4? I think that's what version they're on now.

hallow jacinth
#

because flask-boostrap doesn't support it, and I am too lazy to go and download and use raw bootstrap 4

topaz widget
#

@maiden kraken Sure thing. The basic gist:
CSRF: Exploiting your authentication to make sensitive requests from outside your session.
XSS: Exploiting an insecure web application that allows raw user-generated HTML to inject JavaScript into the application.
SQL injection: Loading SQL (Structured Query Language) commands onto the database, which are not handled property to access or modify information the user shouldn't be able to.

#

Some of these attack methods can be used in tandem.
For instance, XSS can be used to pull credentials (cookies) from another user of the site, which then can be used in a CSRF attack to make privileged requests under the identity of the user whose identity has been stolen.

maiden kraken
#

Since you're fairly advanced, I guess using something like tinyMCE and allowing storing html into your models isnt very safe?

topaz widget
#

Well, nothing I'm working on requires tinyMCE, but I have messed around with it a bit.

#

But yes, I would use something like that so users can't write their own HTML.

#

You can manually "white-list" certain HTML if you want to let users get more creative, but it's a pain in the ass to implement.

maiden kraken
#

it's just scares me since I am using python as a hobby how much stuff you have to know ๐Ÿ™‚

topaz widget
#

It's good that you're scared. There are a lot of ways things can go wrong that won't even cross your mind as a non-expert.

near forge
#

https://github.com/chocotacove/chirp
This is my first complete project, first time writing readme.
Is the readme good, what changes can I do?
@coral raven

"Drop a star" lol, sounds like a youtube video.

topaz widget
#

Even the expert miss vulnerabilities, too.

#

I don't know if you remember the HEARTBLEED vulnerability, but that was a big deal not too many years ago.

maiden kraken
#

I am reading about it, as you said, if you do something there is always a risk

topaz widget
#

It really depends on how secure your application needs to be.

near forge
#

@topaz widget and to answer your questions, django queries are escaped

topaz widget
#

@near forge lol thanks. I'm here for my own security concerns.

#

Anyway, if you're making bank software, that better be airtight.

near forge
#

Before you concern yourself about security, you should ask yourself what you are securing.

topaz widget
#

If you're making some rant blog, it probably doesn't have to have NSA-level security.

maiden kraken
#

thanks for a nice discussion, I g2g

topaz widget
#

np, take it easy.

near forge
#

@topaz widget hopefully you have colleagues and tests before pushing bank software to production.

topaz widget
#

Yes, of course. But even professionals miss things. Kevin Mitnick has entered the chat

#

Better yet: Frank Abagnale has entered the chat

#

Though Abagnale was check fraud.

#

("Catch Me If You Can" was based on his exploits)

near forge
#

Anyhow as in any company, security should be on par with the services you provide.

#

There's really no point in making an air tight social app that no one uses.

topaz widget
#

Um...

#

Might as well get security right from the start, though.

near forge
#

But of course when money is involved. The best thing you can do is implement SOTA protocols for handling it.

#

That's just a waste of time imo.

#

It's an endless task.

topaz widget
#

SOTA? State of the art?

near forge
#

yes, usually there's is someone out there that's thought about security. As in django things are pretty secure if you just follow the guidelines.

#

My point is it's usually a better and easier to use already existing tools than implementing your own security measures.

topaz widget
#

You mean like not writing raw SQL commands, only using the | safe filter when you know you can trust the content, and using csrf_token in all your forms?

near forge
#

I guess, you better read the docs. I don't know them all by heart.

topaz widget
#

Oh yeah, right, there are a bunch of others on their "checklist" I wasn't thinking of (but use)

weak chasm
#

Anyone familiar with httpresponseredirect?
I'm redirecting a user to a google api link, they sign in, authorize access, confirm, etc, then it returns with the "code" necessary in the redirect URL so that I can next fetch a token.
However, it seems that my code might need to pause momentarily until the user finishes all of this stuff. Otherwise, code keeps running and I get errors b/c response not back yet from user's actions.

My question is http response redirect the best tool. or even if it isn't, should i be looking to something like celery to make a task scheduler?

clear fjord
#

Hey guys anyone know how I can run a function at a time specified by the user In flask

topaz widget
#

@clear fjord cron. Not in flask though, in Linux.

#

Actually, wait, maybe cron isn't so good if the user is specifying the time.

clear fjord
#

Yea

#

I was looking for a code solution

#

And since my client is not hosting on his laptop because its a small program just for him

#

if it restarts

#

it also needs to re add the tasks

topaz widget
#

I'm not sure how you would do that from within Flask.

clear fjord
#

Right now im just saving the entries in database

topaz widget
#

Maybe you could use time.sleep() and then just specify the time between when the user made the request and when it's supposed to happen.

clear fjord
#

I was thinking run the function from a url

#

and take an id in the url

#

and run the task depending on id and have another program run the url

#

or something

weak chasm
#

messaging queue maybe?

topaz widget
#

Although, I don't think time.sleep() could be done asynchronously, so maybe that's not such a good idea.

clear fjord
#

let me see if it can be used asynchronously

#

maybe some library or something i dont know

topaz widget
#

Well, you can write an asynchronous function.

clear fjord
#

Yea I can do that

#

and then run the url it runs the function

topaz widget
#

I'm just saying I don't think time.sleep() is natively asynchronous like setTimeout in JavaScript is.

clear fjord
#

node flask hybrid ๐Ÿ˜ณ

topaz widget
#

lol

clear fjord
#

i never used node

topaz widget
#

How tf are you using node with Flask?

clear fjord
#

im not lmao

topaz widget
#

or was that a joke?

#

okay lol

clear fjord
#

i could use node to run functions

#

"the function"

topaz widget
#

It sounds to me like some asynchonous function might be best, but...

clear fjord
#

node has alot of library like that

#

yea ill try that

topaz widget
#

you might run into problems if a lot of users run asynchronous functions.

clear fjord
#

just 1 user

#

its for himself

#

hosting on his laptop

#

he gonna leave running 24/7

topaz widget
#

So this is only for him? And he is admin?

clear fjord
#

yea

topaz widget
#

What OS is he using?

clear fjord
#

windows if im not mistake

#

n

topaz widget
#

Just use task scheduler then.

clear fjord
#

k let me try that

topaz widget
#

Are you on Windows?

weak chasm
#

@topaz widget task scheduler like celery. I'm wondering though are you able to break a function into 2 tasks. like
def main():
task 1 do something
httpresponseredirect
celery wait until http response is back from user completing action on a different url
task 2 do something else
return

topaz widget
#

@weak chasm No, Windows Task Scheduler.

#

This is admin-level stuff. Could just be done right on the system.

#

And it might be better for this guy to use Windows Task Scheduler if he's not a coder himself.

vestal hound
#

Although, I don't think time.sleep() could be done asynchronously, so maybe that's not such a good idea.
@topaz widget it's not; you would use asyncio.sleep in that situation

topaz widget
#

you should ping omar on that message, too.

vestal hound
#

Anyone familiar with httpresponseredirect?
I'm redirecting a user to a google api link, they sign in, authorize access, confirm, etc, then it returns with the "code" necessary in the redirect URL so that I can next fetch a token.
However, it seems that my code might need to pause momentarily until the user finishes all of this stuff. Otherwise, code keeps running and I get errors b/c response not back yet from user's actions.

My question is http response redirect the best tool. or even if it isn't, should i be looking to something like celery to make a task scheduler?
@weak chasm what backend

weak chasm
#

@vestal hound very new to webdev. Idk what you're talking about. lol
I'm using python django with heroku , but not not really using their built in middleware or whatever else they have.(Turned out I like flask more, but too late to go back)

vestal hound
#

@vestal hound very new to webdev. Idk what you're talking about. lol
I'm using python django with heroku , but not not really using their built in middleware or whatever else they have.(Turned out I like flask more, but too late to go back)
@weak chasm so Django is your backend

#

vanilla Django or DRF?

weak chasm
#

how do i check?

vestal hound
#

if you don't know, it's vanilla Django

#

DRF = Django REST Framework

weak chasm
#

oh vanilla

vestal hound
#

so basically

#

you have a view where you need to do two things: get some data from somewhere else, and get some data from the user

#

and you only want to proceed after both of these things have been done

#

correct?

weak chasm
#

Haven't gotten that far. Was writing helper functions in another file to be called in views.py I guess. will have to figure out if I need to do something with models.py and displaying data to my index.html page

#

so yes

vestal hound
#

huh.

#

why do you want to use a redirect then

#

seems a bit complicated

#

async views should work just fine

#

actually, wait, let me think

weak chasm
#

I need the user to login to their google account and confirm authorization for my web app so I can get token access in future and play around with that stuff.

vestal hound
#

feels like

#

you're trying to solve multiple problems at once

#

maybe you can list out the steps in the intended experience from the user's perspective

weak chasm
#
  1. type my webapp url into browser
  2. my web app will redirect you to google api website so you can login and confirm access to my application
  3. user should be taken back to the my webapp.
  4. I will take the code embedded within the redirect url to fetch the token to have future access of the application
  5. list emails or list file in drive for the user
  6. do some magice on emails and files to create some end product for user
  7. user does some stuff
#

? i guess O_o

vestal hound
#

hm

#

okay

#

so where is it that you are thinking "what if the user's not done?"

weak chasm
#

oh i added 5-7

#

ohhh so if the users not done:

#

the problem is that how does my web app know how fast or slow the user is when loggin into their account and checkboxing the stuff in google api .com website or w/e the url is. my code redirects sure but it keeps going and is thinking it already has the redirect url with the embedded code needed to fetch token. but it doesn't b/c user is slower than a computer executing lines of consecutive code.

vestal hound
#

ah, okay

#

because

#

you have redirected

#

so you don't know if the user is done.

#

is that what you mean?

weak chasm
#

so
httpresponseredirect(url) --> user goes through the motion of loggin in at google.com
code= request(url).url or something ==> user is not done yet with loggin in&authorizing
code. split("&") --> user is still not done
*here computer throws error variable called 'code' does not have more than 1 element in the list or ssomething like that *

vestal hound
#

hm

#

but

#

you are returning a HttpResponseRedirect

#

right?

weak chasm
#

correct

vestal hound
#

so there shouldn't be code running in your view after that...?

#

because you've already returned

weak chasm
#

i didn't return

#

O_O

#

is that function only to be used with views.py

#

O_O

vestal hound
#

well, then your redirect won't work, if I understand what you're saying correctly

#

it's not a function, it's a type of Response

#

do you know how HTTP status codes work?

weak chasm
#

I know of them. not sure how the codes affect the views.py

#

like 404 not found and 500 you messed up

vestal hound
#

yup

#

so basically

#

you know how your views

#

return responses?

#

HttpResponseRedirect is just another kind of response, but with a special status code that tells the browser that receives it "hey go here"

#

it's not a function thaty ou call

weak chasm
#

o_o

#

woah

#

my views return responses?

#

return render(request,"index.html")

#

i guess that's a response

#

should i be making a views.py helper function that just redirects

#

and I don't have to worry about the async responses

#

I'm going to try to break up function so I return httpresponseredirect

#

thanks

vestal hound
#

yes, render returns a HttpResponse

topaz widget
#

@weak chasm Are you trying to render templates to JSON or something? What are you trying to do?

#

If you're using Django, there are some native functions for doing simple redirects.

#

If that's all you're trying to do.

weak chasm
#

writing the oauthorization code to ask user to go to google api website(automated not manually) they login and confirm access then it comes back w/ redirect with "code" value within the redirect url. i take that to complete the token fetching process so in the future I dont have to ask the user again. and i'm able to read/write files in say gmail now

I didn't know/ still a bit uncertain how views handles httpresponses, (just know that they do and will be using this fact forward) and then send that to my page index.html. I saw some examples that were deprecated/only for flask that made a class inside models.py.

topaz widget
#

I don't think you can do that with gmail.

weak chasm
#

you can automate it. you just have to have the user login once at the beginning manually.

topaz widget
#

The user would at the very least have to change a setting in their gmail account.

#

I think that would require "allowing insecure apps" to access your gmail via something like SMTP.

#

idk, maybe there is an API, though. I guess there could be.

weak chasm
#

there is a google api for server side web applications. even some example code for flask(not django) interestingly enough, after searching for some examples, I found that the google's api authlib i think or something had some sample code for django in git repo. they deleted it. and aren't updating it only maintaining it. even more interesting, the old sample code was for using google plus. so i'm thinking the security fiasco w/ google plus couple years back made them ctrl+f google plus delete all.
change the setting=> yes. was thinking of even automating this one time sign with selenium. but that's too much work not enough reward.
https://developers.google.com/gmail/api/auth/web-server
that one seems more complicated than the one for drive

plucky tapir
#

You can have a basic html web page and then have python scripts to make things happen on the page? Or how can I integrate python to html exactly

topaz widget
#

@plucky tapir I think you want to use JavaScript for what you're thinking about. Python is used on the "back-end".

#

Python is used on the server (back-end) to serve up HTML, CSS, and JavaScript (and media) files to the client or browser or front-end.

#

Sounds like you're just getting started on your web development journey.

#

That's why these forums exist, though.

plucky tapir
#

Is there a big learning curve for JavaScript? Mainly have to function rather than look nice.
So assuming a basic webpage was built. That had made up user information stored in a database. Iโ€™d use python to pull that data, do something to it (add 1.3 % increase for example) and use front end to display it?

topaz widget
#

that's pretty much right.

#

It's pretty easy to get started with JavaScript but there is a long path to becoming very good with it. Same with Python.

#

Here's a little more detailed run-down of what each component does in the "web stack":

plucky tapir
#

Yeah just c++ for me and some concepts with python. Never implemented any of it to actually create something before though

topaz widget
#

HTML: Formats content on a web page. Used for semantic (meaning) and formatting purposes to mark content (called markup)
CSS: Styles HTML content. HTML tags are queried with CSS to apply styling to different HTML elements.
JavaScript: Manipulates the behavior of content on a web page. Can run full programming logic including loops, conditional statements, etc...
Python or Other Backend Language: Serves up content. Accesses database, crunches numbers before sending content to frontend. Processes requests sent from client (frontend)

plucky tapir
#

JavaScript can sometimes serve as a backend then if youโ€™re real into it?
What section of python would I want to look into more for this type of backend with python?

C++ isnโ€™t really useful here it looks like

zealous siren
#

@plucky tapir it can serve as backend completely

plucky tapir
#

@zealous siren with JavaScript?

zealous siren
#

yes

#

NodeJS

topaz widget
#

@plucky tapir Some people swear by JavaScript (running on a Node.js runtime) for back-end, as it streamlines the development process only needing to use one language for both front and back-end (only JavaScript can run on the front-end).

#

I don't know if it's really comparable to C++, but C# is a popular language for the web back-end using Microsoft's .NET framework.

#

I'm not sure what you mean by "section" of Python, but there are some popular Python web development frameworks, notably Flask and Django.

zealous siren
#

also FastAPI

native tide
#

hello

#

I am making a google extension

#

is there a way to write and read to files in vanilla js

#

i only found stuff that works in node

#

i am noob

#

forgive

zealous siren
#

Node is Javascript

#

and try Javascript Discord Server

native tide
#

i dont know where it is

#

can u give link

zealous siren
#

nope

native tide
#

when i tried exporting a file, it said it was an invalid token

#

export is invalid token

zealous siren
#

Javascript is offtopic

native tide
#

wdym

proper hinge
#

Well, not necessarily. It's fine if it's related to something you're doing in Python. But, for example, talking about using nodejs to run a webapp or use js to make a chrome extension are not really on topic here

lament sapphire
#

This may not be the right channel, it's a Git questions. Please...
Hi, I've never gotten this message when i've made a commit in the pawst.

  1. Why would this occur?

  2. Should I suppress it? or what should I do?
    [master 189a579] Content is showing over the foreground image, but footer is still risng above overflowing, and content is overlapping strangely.
    Committer: Brian Boros Bpower@tests-MBP.attlocal.net
    Your name and email address were configured automatically based
    on your username and hostname. Please check that they are accurate.
    You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

git commit --amend --reset-author

1 file changed, 1 insertion(+), 1 deletion(-)

proper hinge
#

No it's not the right channel. git is not related to web development

lament sapphire
#

Thanks I'm new to the pyton group and will be more active soon, but thanks a ton.

#

learn the ettique I read the rules...

plucky tapir
#

@topaz widget Iโ€™ll jump into flask framework to start learning how to get the database data and do something with it. From there html can use it to output on a page?

topaz widget
#

more or less, yes @plucky tapir

#

Just don't set your sights too high this early on. Learning this stuff takes time.

versed python
#

Django Rest Framework: How many requests is too many?

I have a page on my frontend which shows 10 Posts. Each of them is associated with multiple Tags and Images. And all this data needs to be fetched from multiple different views. So when I load up this page in my browser about 20 requests are made to my backend. Is this normal/okay?

If it isn't, then what can I do to minimize them?

I am using Vuejs as my frontend if that matters.

#

Please @ me when you reply

plucky tapir
#

@topaz widget Okay thanks. I've been using nano for python. Should I be looking into IDE's for this? I'm looking It looks like VS code and pycharm is the most popular recommended. I'll be looking at sql + python tutorials for now

topaz widget
#

@plucky tapir vscode is pretty popular. That or Pycharm would be good options.

plucky tapir
#

@topaz widget my bad for all of the questions. One last thing I was wondering, a user on a website (made by html) inputs data. Would it need python to get pushed to the database?

topaz widget
#

@plucky tapir You've got a lot to learn. First of all, all websites with user interfaces use HTML on the front-end. HTML gives different elements on a webpage their special meaning. One such element that has special meaning is called a <form> element. This form element is how users submit data from a web page to the back-end for something like Flask or Django to enter into the database. In answer to the other question, Python, or more specifically a framework like Flask or Django, would have some protocols for entering that data into the database. So, essentially you're correct, but there is a lot more to it. Anyway, I'm happy to answer questions, but a new episode of "The Boys" just dropped, so I'm going to log off Discord for now. Keep asking questions. That's the right approach.

tepid lark
#

@versed python I try and batch as much as possible.

topaz widget
#

@versed python 20 requests for a page (with all the content) is not too much. I'm not sure this is something to be concerned about unless your application feels laggy.

#

I think you'll know when you're asking too much from your application.

tepid lark
#

20 requests for a page isn't bad, unless that number of requests can scale

topaz widget
#

There may be ways to combine the page into fewer requests (that's beyond me), which may take out some of the overhead associated with each 'handshake', but I don't think you're anywhere close to having to worry about that.

stable kite
versed python
#

@topaz widget @tepid lark thanks for your insights. However you mentioned "batching". What is that? Can you explain it a bit or provide some links?

vestal hound
#

Django Rest Framework: How many requests is too many?

I have a page on my frontend which shows 10 Posts. Each of them is associated with multiple Tags and Images. And all this data needs to be fetched from multiple different views. So when I load up this page in my browser about 20 requests are made to my backend. Is this normal/okay?

If it isn't, then what can I do to minimize them?

I am using Vuejs as my frontend if that matters.
@versed python are you making one request per instance?

#

why canโ€™t you fetch everything you need together?

topaz widget
#

Good point, as it's an API

vestal hound
#

20 requests seens to imply at least 20 queries.

topaz widget
#

It should all just come as one JSON string.

vestal hound
#

and yeah, if that can scale you will probably have a problem down the road

topaz widget
#

How so? @vestal hound

vestal hound
#

How so? @vestal hound
@topaz widget I mean, that number of queries

#

like N+1

#

not what you said about JSON

topaz widget
#

Oh, okay. Yeah, I mean, 20 isn't terrible for an entire page including media, though, is it? @vestal hound

#

Granted, I don't use DRF, but I see the requests using Django in the standard manner, and it can be quite a few if there are a lot of pictures.

vestal hound
#

well

#

I took it as 20 on initial load for just data (like models)

#

which would be a huge lot

#

if itโ€™s 20 over time due to scrolling or something + including one per image + fetching other stuff separately

#

then I would say itโ€™s fine

topaz widget
#

So you're talking about AJAX calls?

vestal hound
#

yup, basically

topaz widget
#

I mean, I guess it's all AJAX with an SPA

vestal hound
#

although

#

yeah, that

topaz widget
#

Wait, you mean, it's all AJAX?
Always has been.

#

lol

versed python
#

I don't really know how to do that

#

why canโ€™t you fetch everything you need together?
@vestal hound this I mean

#

I am limited by my serializers and since I am using viewsets a lot, that also means I have to send requests to different paths of drf

#

Is there a better way?

vestal hound
#

I am limited by my serializers and since I am using viewsets a lot, that also means I have to send requests to different paths of drf
@versed python oh

#

well

#

that's why I guess

#

you know how to write nested serializers?

#

that's probably what you want

versed python
#

can I do something about it?

vestal hound
#

yes

#

you need to modify your serializers

versed python
#

nested serializers?

vestal hound
#

yes

#

okay like imagine

versed python
#

I don't know them

vestal hound
#

you have this data model

versed python
#

I guess ill have to look at em

#

Does django graphene make this stuff easier or does it remain the same?

vestal hound
#

wait, this doesn't make any sense

#

I just woke up

#

let me get some water and I will fix the example

versed python
#

Yeah sure, take your time

#

Or you can just tell me what link to look at, I will try to learn from there

native tide
#

anyone how to create a azure server replica in your linux machine ?

vestal hound
#
class Song:
    artist = models.ForeignKey(Artist, related_name='songs', delete=models.CASCADE)
    name = models.TextField()
    lyrics = models.TextField()

class Artist:
    name = models.TextField()
    date_of_birth = models.DateField()
lethal orbit
#

Does django graphene make this stuff easier or does it remain the same?
@versed python I found it to be horribly hard to read and extend, and recommend ariadne instead.

vestal hound
#

so say you have this, right

#

each song has an artist, and each artist has multiple songs

lethal orbit
#

But GraphQL as a whole makes it very easy to fetch all the data in one query.

versed python
#

@versed python I found it to be horribly hard to read and extend, and recommend ariadne instead.
@lethal orbit I looked at it the other day on your recommendation and could only find photos of some greek goddess(?)

vestal hound
#

so you'd have an ArtistSerializer and a SongSerializer

#

Google "ariadne graphql"

versed python
#

Oh

vestal hound
#

the thing is

#

you can put serializers in serializers

versed python
#

Ok, so tell me should I go with this aridne or nested serializers approach

vestal hound
#

by default, related models are serialized with PrimaryKeyRelatedSerializer

#

Ok, so tell me should I go with this aridne or nested serializers approach
@versed python up to you

#

GraphQL is more foreign but (I would say) more powerful

versed python
#

Which one is better?

vestal hound
#

there's no "better"

#

go with what is right for you

versed python
#

But GraphQL as a whole makes it very easy to fetch all the data in one query.
@lethal orbit This does make it seem "better"

vestal hound
#

REST as a style

#

is honestly quite foreign

#

to most people

#

so one tends to end up writing RPC code

#

which is fine, but not REST

versed python
#

Yeah it is difficult I must say

#

RPC Code?

vestal hound
#

so I guess what you got was something like

lethal orbit
#

GraphQL is more modern and powerful. REST has been around forever, and many jobs still expect it. I wouldn't use it in a new project, tbh.

vestal hound
#

{'name': 'some_artist', 'date_of_birth': '1963-03-05', 'songs': [1, 8, 34, 494, 2395]} from your serialized Artist

lethal orbit
#

But REST isn't bad, of course.

versed python
#

GraphQL is more modern and powerful. REST has been around forever, and many jobs still expect it. I wouldn't use it in a new project, tbh.
@lethal orbit But I have seen you using them in projects

vestal hound
#

true REST is really hard to write iMO

versed python
#

{'name': 'some_artist', 'date_of_birth': '1963-03-05', 'songs': [1, 8, 34, 494, 2395]} from your serialized Artist
@vestal hound Yeah go on

vestal hound
#

and quite unintuitive

#

@vestal hound Yeah go on
@versed python and then

lethal orbit
#

I have used both, yes ๐Ÿ™‚

vestal hound
#

you probably loop through those song IDs

lethal orbit
#

DRF was an older project haha

versed python
#
class Song:
    artist = models.ForeignKey(Artist, related_name='songs', delete=models.CASCADE)
    name = models.TextField()
    lyrics = models.TextField()

class Artist:
    name = models.TextField()
    date_of_birth = models.DateField()

@vestal hound (For reference)

vestal hound
#

and get songs one by one and put them into the SongSerializer

#

but you can also do this

#
class ArtistSerializer(serializers.ModelSerializer):
    songs = ...a custom serializer for a queryset of songs...
    ...your other fields...

    class Meta:
        model = Artist
        fields = ['songs', 'name', 'date_of_birth']
#

so that when you serialize your Artist, it becomes a nested JSON

versed python
#

oh wow

#

So thats like HyperLinkedModelSerializer but cooler?

vestal hound
#

like:

{
  'name': 'some_artist', 
  'date_of_birth': '1963-03-05',
  'songs': [
    {
      'id': 1,
      'name': 'some_song'
      ...
]}
#

yes

versed python
#

Great

vestal hound
#

HyperLinkedModelSerializer basically returns a URL saying "go here for more details about this resource"

versed python
#

that doesn't look too difficult to implement

vestal hound
#

well.

#

๐Ÿ™‚

#

I mean

#

it's a good part of the learning process

#

I had hell with these things a couple of months back

versed python
#

Well I am having hell now ๐Ÿ˜ƒ

vestal hound
#

yeah

#

it's a bit unintuitive

#

the thing about REST is that

#

it's a bit...

versed python
#

ANd javascript is shit but I have to write it anyway

vestal hound
#

different

#

and like

#

if you try to write code that does not conform to the REST paradigm

#

you will start fighting the framework

#

which is painful

versed python
#

There's a paradigm??

vestal hound
versed python
#

God

vestal hound
#

technically REST is a way to write APIs

versed python
#

why is everything so difficult lol

vestal hound
#

you don't have to follow it

#

you can just write an RPC API

#

so basically like

#

think of your application as a Python module

#

and each view as a function in it.

#

that is fine.

#

REST is a different way of thinking about APIs

#

in terms of resources

#

and operations on them

#

and it's really a bit technical and after a while you'll start thinking "why must hypermedia be the engine of application state" etc. etc.

versed python
#

Lol, I am probably not too good to get to that stage yet

stable kite
versed python
#

Anyways thanks @vestal hound , I will look into the resources you sent. Thanks

vestal hound
#

yw

marble carbon
#

GraphQL is more modern and powerful. REST has been around forever, and many jobs still expect it. I wouldn't use it in a new project, tbh.
@lethal orbit I think one drawback of using GraphQL with Relational Database is that you can't optimize the database queries anymore, unless there is a way that I'm unaware of

lethal orbit
#

Optimize how?

marble carbon
#

okay let's say in a given serializer, I know that I'll be providing so and so foreign key data, so I'll be using joins to return those values from the View.

#

but in GraphQL, the user can query whatever the fields and data they like

lethal orbit
#

If you have data with joins (foreign keys, many to many), you can still use prefetch or select related in your query, and add that field as a resolver...

vestal hound
#

If you have data with joins (foreign keys, many to many), you can still use prefetch or select related in your query, and add that field as a resolver...
@lethal orbit which is equally necessary in all cases, anyway

#

it's not a problem particular to GraphQL

marble carbon
#

so I'll be writing cases in my view that'll check whether the given field is present in query sent by the client and create joins in those scenarios only?

vestal hound
#

so I'll be writing cases in my view that'll check whether the given field is present in query sent by the client and create joins in those scenarios only?
@marble carbon a library should handle that

#

and provide an appropriate abstraction

marble carbon
#

ohhh they do? that'd be nice

worn rapids
#

I recently made a Web API that implements both GraphQL and REST endpoints, if you'd like an example. Implemented via FastAPI: https://docs.coursecake.tisuela.com/REST-API

gentle lark
#

im trying to install twisted and i keep getting erros and im wondering what i should do

#

im running python 3.8

#

feel free to @ me

verbal obsidian
#

If you don't post the errors we can't hardly help you

lethal orbit
#

@gentle lark yup. Post error log. I just installed it in a clean venv and it worked fine.

#

(I actually did need to start a project with it lol)

verbal obsidian
#

Lol

gentle lark
#

@lethal orbit i think its because i might have python 32 bit by accident

#

i think i can upgrade to 64 bit and it should work

lethal orbit
#

Try it and let us know I guess

gentle lark
#

@lethal orbit installed 64 bit but error persists

#

so im gonna try to reinstall the c++ build tool from vs to see if that fixes it or not

maiden kraken
#

Hello, this is useful in django:
ModelName.objects.last()
but I would like to access date_of_publication field, this returns str method

#

meaning i need to go deeper into model, return field that I want, how do I do that?

#

well I am an idiot... You do just:
ModelName.objects.last().date_of_publication
but you have to make sure that there is actually an object to return because you may get NoneType and wonder why it isnt working ๐Ÿ˜„

versed python
#
class Post(models.Model):
    author = models.ForeignKey(
        'accounts.CustomUser', on_delete=models.CASCADE, related_name='post_author'
    )
class PostImage(models.Model):
    image = models.ImageField(
        _("An image to go with your post"), upload_to=user_directory_path
    )
    post = models.ForeignKey(
        "posts.Post", on_delete=models.CASCADE,
        verbose_name=_("The post that the image is associated with")
    )
#

i know I can add multiple PostImage to Post using

post = Post.objects.get(id=1)
images = PostImage.objects.all()[:10]
for image in images:
    post.postimage_set.add(image) 

However, I was wondering if there was a better way of doing this without making a for loop? I was thinking about post.postimage_set.bulk_update but that did not work.

maiden kraken
#

that is not related and I hope you don't mind, why do you have "posts.Post" instead of "Post"?

versed python
#

that is not related and I hope you don't mind, why do you have "posts.Post" instead of "Post"?
@maiden kraken That is another method of describing an FK. This way, as you can see in Post.author, i don't have to import the CustomUser model. Django can figure out what model you are referncing to by itself. this is a better way imo.

#

you can reference another model by '<app-name>.<model-name>' or just '<model-name>' if your models are uniquely named (which they should be).

maiden kraken
#

okay thanks a lot for explanation

marble carbon
#

@worn rapids github link pls?

native tide
#

hi EveryBody ๐Ÿ˜Š,

someone for helps?

i create data in my test environnement.

i use it to confirme the file is delete when i use the value of delete !
it work ! but not on the good side because my date is delete for real.

so i search on the web ! but i donโ€™t found how can i get a copy of the file in my test environnement ( pytest / pyramid ) in init.py TEST_Zip2 = join(dirname(file), โ€˜UnZipโ€™, โ€˜test2.zipโ€™)

tacit comet
#
#layout.html
<a class="dropdown-item" href="{% url 'login'  %}">login</a> 

#urls.py
urlpatterns = [
    path('register/',views.register,name = "register"),
    path('login/',views.loginUser,name = "login"),
    path('logout/',views.logoutUser,name = "logout"),
]

when i runserver NoReverseMatch at /
Reverse for 'login' not found. 'login' is not a valid view function or pattern name.

#

whats wrong here ๐Ÿ˜ฆ

maiden kraken
#

in urls.py do you have app_name = 'something'? If so you need to pass to template href="{% url 'something:login' %}

tacit comet
#

'appname' is not a registered namespace

#

i registered app name in urls.py but im missing something

zinc hill
#

maybe you didnt add it to the INSTALLED_APP?

vestal hound
#

@versed python wait, hold up; how do those PostImage instances exist without a Post, originally?

tacit comet
#

maybe you didnt add it to the INSTALLED_APP?
@zinc hill added

#

i think i have problem with main app in urls.py

versed python
#

@versed python wait, hold up; how do those PostImage instances exist without a Post, originally?
@vestal hound I haven't but any db level constraints in place but I don't give my users ability to add PostImage without a Post first

vestal hound
#

@vestal hound I haven't but any db level constraints in place but I don't give my users ability to add PostImage without a Post first
@versed python huh. I would've thought ForeignKey fields were non-nullable by default

#

why didn't bulk_update work for you?

zinc hill
#

@tacit comet what about the
Applicationname url?
did you point it to the your new app?
for ex: project call "food"
and you made anotehr app called "account"
did you change the food.urls to point to "account.urls"?

versed python
#

why didn't bulk_update work for you?
@vestal hound idk how it works. Will it work for my use case? then I will read up the docs a bit.

vestal hound
#

it should

#

if I understand correctly

strange briar
#

hey guys, i'm building a web app and i'd like to check if the emails provided actually exists, i use this library
https://pypi.org/project/py3-validate-email/
but the parameter

check_mx: check the mx-records and check whether the email actually exists

can anyone tell me how to resolve that or has another library to propose me ?

tacit comet
#

@tacit comet what about the
Applicationname url?
did you point it to the your new app?
for ex: project call "food"
and you made anotehr app called "account"
did you change the food.urls to point to "account.urls"?
@zinc hill i handle it thank you

versed python
#

hey guys, i'm building a web app and i'd like to check if the emails provided actually exists, i use this library
https://pypi.org/project/py3-validate-email/
but the parameter

check_mx: check the mx-records and check whether the email actually exists

can anyone tell me how to resolve that or has another library to propose me ?
@strange briar what do you want to resolve?Just use check_mx=True in the validate_email function

strange briar
#

yes Ignis that's what i did yet it doesn't work, keeps running

#

nvm it works it's just that it's slow

#

anyways to implement a faster verification ? or should i just use regex

marble carbon
#

oh this tool

#

is good, but too slow

strange briar
#

yes way too slow

marble carbon
#

but like you'd usually just use it on the registration form

#

so 5 secs at max?

strange briar
#

yea but i can't let a user wait 4-5 secs on registration form

marble carbon
#

hmm, use ajax

#

validate the email on blur

strange briar
#

so this must be done via front-end in your opinion ?

marble carbon
#

I mean r u using flask?

#

or django?

tacit comet
#
<a class="dropdown-item" href="{% url 'student:register'%}"> register </a>
{% endif %}```
#

there is any easy way about this ? ๐Ÿ˜„

marsh canyon
#

can't think of any

#

its fine to have logic in the navbar section tho

#

but u should try to implement logic in view mostly

#

in ur case, u can't really do that inside the view, hence in the template

versed python
#

anyways to implement a faster verification ? or should i just use regex
@strange briar Do you need to verify the email exists? Then this is your best bet. Otherwise use with check_mx=False it will be pretty okat

#

Oh wait, i just checked. Turns out I don't use this library at all @strange briar I use validate-email. pip install validate-email

strange briar
#

yea i checked your implementation too and validate-email is not up to date, it doesn't use py3dns

versed python
strange briar
#

so the alternative is to use this

#

pretty much the same as the previous one

#

they all do the same job but the speed remains the same

versed python
#

it does implement pydns

strange briar
#

it display an error if you use the check_mx

#

you didn't implemented it so you didn't see it but i did

#

it's default to False

versed python
#

yes I do remember that

#

thought it was just an issue with my pc

#

well good to know

#

ill change my dependencies too accordingly, thanks

strange briar
#

np

#

@marble carbon i'm using django

marble carbon
#

oh well, you can write a custom endpoint that accepts an email and return its validity only 8n json response, and then you can call it from ajax on your page

strange briar
#

i see thank you thunder ๐Ÿ™‚

#

i've got another question i'm implementing some basic testings on django test for my user table

#

and i get errors while i shouldn't

#
from django.test import TestCase

from .models import CustomUser

# Create your tests here.

class CustomUserTestCase(TestCase):
    """ Base user table testing """

    def setUp(self):

        # Create valid users
        user1 = CustomUser.objects.create(first_name="John", last_name="Doe", email="test1@gmail.com")
        user2 = CustomUser.objects.create(first_name="Jane", last_name="Doe", email="test2@Outlook.com")
        user3 = CustomUser.objects.create(first_name="Brian", last_name="Yu", email="test3@yahoo.fr")

        # Create invalid users
        user4 = CustomUser.objects.create(first_name="", last_name="Doe", email="test4@live.fr")
        user5 = CustomUser.objects.create(first_name="Jane", last_name="", email="test5@Outlook.fr")
        user6 = CustomUser.objects.create(first_name="John", last_name="Doe", email="")
        user7 = CustomUser.objects.create(first_name="Jane", last_name="Doe", email="test@.com")
        user7 = CustomUser.objects.create(first_name="John", last_name="Doe", email="test@O.")


    def test_valid_CustomUsers(self):

        self.assertTrue(user1.is_valid_CustomUser())
        self.assertTrue(user2.is_valid_CustomUser())
        self.assertTrue(user3.is_valid_CustomUser())


    def test_invalid_customUsers(self):

        self.assertFalse(user4.is_valid_CustomUser())
        self.assertFalse(user5.is_valid_CustomUser())
        self.assertFalse(user6.is_valid_CustomUser())
        self.assertFalse(user7.is_valid_CustomUser())
#

and here are the logs

#
System check identified no issues (0 silenced).
EE
======================================================================
ERROR: test_invalid_customUsers (users.tests.CustomUserTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/leon/pers/Boutique-Leon/backend/users/tests.py", line 34, in test_invalid_customUsers
    self.assertFalse(user4.is_valid_CustomUser())
NameError: name 'user4' is not defined

======================================================================
ERROR: test_valid_CustomUsers (users.tests.CustomUserTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/leon/pers/Boutique-Leon/backend/users/tests.py", line 27, in test_valid_CustomUsers
    self.assertTrue(user1.is_valid_CustomUser())
NameError: name 'user1' is not defined

----------------------------------------------------------------------
Ran 2 tests in 0.010s

FAILED (errors=2)
Destroying test database for alias 'default'...
versed python
#

self.user1.assert...

#

you forgot the self

strange briar
#

oh ok so the syntax should be like that

self.user1.assertTrue(user1.is_valid_CustomUser())
``` ?
versed python
#

every where you reference something from another class method, you must write self

#

oh ok so the syntax should be like that

self.user1.assertTrue(user1.is_valid_CustomUser())
``` ?

@strange briar self.assertTrue(self.user1.is_valid_CustomUser())

strange briar
#

still 2 errors

#
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
EE
======================================================================
ERROR: test_invalid_customUsers (users.tests.CustomUserTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/leon/pers/Boutique-Leon/backend/users/tests.py", line 34, in test_invalid_customUsers
    self.user4.assertTrue(self.user4.is_valid_CustomUser())
AttributeError: 'CustomUserTestCase' object has no attribute 'user4'

======================================================================
ERROR: test_valid_CustomUsers (users.tests.CustomUserTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/leon/pers/Boutique-Leon/backend/users/tests.py", line 27, in test_valid_CustomUsers
    self.user1.assertTrue(self.user1.is_valid_CustomUser())
AttributeError: 'CustomUserTestCase' object has no attribute 'user1'

----------------------------------------------------------------------
Ran 2 tests in 0.016s

FAILED (errors=2)
#

looks like the same

versed python
#

see edit above @strange briar

#

You might also have to use self.user1 = CustomUser.objects

strange briar
#

ok great it works ๐Ÿ™‚

#

yes i did implemented that too

#
class CustomUserTestCase(TestCase):
    """ Base user table testing """

    def setUp(self):

        # Create valid users
        self.user1 = CustomUser.objects.create(first_name="John", last_name="Doe", email="test1@gmail.com")
        self.user2 = CustomUser.objects.create(first_name="Jane", last_name="Doe", email="test2@Outlook.com")
        self.user3 = CustomUser.objects.create(first_name="Brian", last_name="Yu", email="test3@yahoo.fr")

        # Create invalid users
        self.user4 = CustomUser.objects.create(first_name="", last_name="Doe", email="test4@live.fr")
        self.user5 = CustomUser.objects.create(first_name="Jane", last_name="", email="test5@Outlook.fr")
        self.user6 = CustomUser.objects.create(first_name="John", last_name="Doe", email="")
        self.user7 = CustomUser.objects.create(first_name="Jane", last_name="Doe", email="test@.com")
        self.user8 = CustomUser.objects.create(first_name="John", last_name="Doe", email="test@O.")


    def test_valid_CustomUsers(self):

        self.assertTrue(self.user1.is_valid_CustomUser())
        self.assertTrue(self.user2.is_valid_CustomUser())
        self.assertTrue(self.user3.is_valid_CustomUser())


    def test_invalid_customUsers(self):

        self.assertFalse(self.user4.is_valid_CustomUser())
        self.assertFalse(self.user5.is_valid_CustomUser())
        self.assertFalse(self.user6.is_valid_CustomUser())
        self.assertFalse(self.user7.is_valid_CustomUser())
        self.assertFalse(self.user8.is_valid_CustomUser())
#

looks like that now

versed python
#

btw this is not django stuff, this is python basics

strange briar
#

actually

#

that's why it's not correctly implemented

versed python
#

you might have to brush up on basics a bit

strange briar
#

i know about asserts

#

the way i implemented it following you is that i create an object

#

i keep this object and then i reference it directly

#

what i want to do is create this user

#

and then directly reference it on test_valid_customers via the db

#

i have to use something like this

#

def test_departures_count(self):
a = Airport.objects.get(code="AAA")
self.assertEqual(a.departures.count(), 3)

#

not repeat self

versed python
#

within methods that's fine. But you're referencing your across different methods

fallen mango
#

I m trying to build a chatbox /messaging app
But Django channels documentation ask for Docker installation for redis
Is it necessary?
I dont want to deploy the project ,just learning

lethal orbit
#

Replied ^ on the Django server lol

fallen mango
#

Srry๐Ÿ˜…

frosty abyss
#

I have one problem that is failing to be googled out. I have a django website and I'm working on its SEO, so atm I'm doing everything to make the website faster, and my last step is implementing CDN. Cloudflare is strongly recommended but I can't accept it for privacy reasons, as it is a man in the middle, having all user data flow in plain text on their servers. I don't think they really do anything bad with the data, but using it would require GDPR box appearing and user accepting it, which I don't want to force him to do. Is it possible to use some CDN type solution to serve static files only? So basically I only care about the speed-up without any other things like ddos protection while protecting user privacy fully.

#

I see a lot of people finding this issue with cdns on reddit, but there are no possible solutions suggested, are there really no alternatives?

lethal orbit
#

You can do that fairly easily....

#

You're using Django templates?

#

I don't, but I think you basically have to set the statics settings to point to something like https://cdn.yourdomain.tld and point that to the CDN.

frosty abyss
#

Really, that's it? :D

#

So I wouldn't even need to modify references to static files from within templates?

lethal orbit
#

Should be it, yeah ๐Ÿ™‚

#

But as I said, I don't use templates.

frosty abyss
#

Thanks then, I'll read up on it. You use django without templates?

#

What are you using django for then?

lethal orbit
#

APIs

#

GraphQL usually. Some REST.

marsh canyon
#

Drf?

lethal orbit
#

Ariadne

#

is my lib of choice.

vestal hound
#

Ariadne
@lethal orbit the "Greek goddess"?

#

๐Ÿค”

frosty abyss
#

Haven't done those things yet

lethal orbit
#

Probably named after her, I dunno lol.

vestal hound
#

it was a joke

#

@lethal orbit I looked at it the other day on your recommendation and could only find photos of some greek goddess(?)
this

lethal orbit
#

Thought that was the case

#

Ok, time to watch the Vue.js announcement,...

#

I bet it's Vue 3

bright spindle
#

quick question on django

#

i want to somehow make people unable to register usernames with similiar case sensitivity

#

e.g. people cant register as Jake if there already exists JAke

vestal hound
#

e.g. people cant register as Jake if there already exists JAke
@bright spindle validator on the username field

bright spindle
#

is that the best way

vestal hound
#

combined with check constraint at the database level

bright spindle
#

would it be the most ideal way

#

i still do want to keep the case sensitive username

#

but i dont want other users to have it

#

e.g. registering Jake allows noone to use JAke and other similiar names

vestal hound
#

actually, no, wrong constraint

#

not a check constraint, a unique constraint

bright spindle
#

however logging in allows Jake to type in JAke, and it will always be displayed as Jake

frosty abyss
#

With validator, as gm wrote, you can write whatever python function

vestal hound
#

however logging in allows Jake to type in JAke, and it will always be displayed as Jake
@bright spindle that's a presentation layer concern

bright spindle
#

is there any documentation to lead me the way

vestal hound
#

not a check constraint, a unique constraint
@vestal hound this is a bit complex though

#

so you should probably go wit hthe validator

#

it's not perfect

#

but it's a lot easier.

#

in general you want to enforce this kind of restriction as deep as possible

bright spindle
#

arent unique constraints very strict

vestal hound
#

and you can't go deeper than the database

bright spindle
#

i know postgresql

vestal hound
#

arent unique constraints very strict
@bright spindle yes, a case-insensitive unique constraint on username

frosty abyss
#

Google django custom form validation

bright spindle
#

also is it more ideal to store a column with the case sensitive username

#

and let the web handle it

#

or have two columns

#

one case sensitive and one case insensitive

vestal hound
#

wait, go back

#

so how do you want them to log in?

#

should logging in be case-insensitive?

bright spindle
#

case sensitive

#

but the username should never be used no matter the case sensitiveness

vestal hound
#

huh

bright spindle
#

an username e.g. Jake

vestal hound
#

so which is it

#

I'm not talking about

#

tat

#

that

#

I mean

#

solely when logging in

bright spindle
#

case insensitive

vestal hound
#

then

#

why don't you just store

#

the lowercase version

#

always

#

and have a unique constraint on that

bright spindle
#

cause i like challenges

vestal hound
#

hm

#

all right

worn rapids
versed python
#

it was a joke
@vestal hound It actually wasn't. really happened to me lol.

marble carbon
#

ty

wanton tulip
#

Question, does somebody know why it's not heading to index.html? Or is this even the right way?.. I will add a second image what shows maybe a bigger or different problem, but I am not sure. Hopefully some of you know. Thanks in advance

wanton tulip
#

UPDATE: have enabled debug mode, and showed that I needed to install eventlet, have done that and now it's showing this.

cyan violet
wanton tulip
#

Thanks for that 1. But I am having still the same problem. Do you maybe know what I am encountering?

nimble epoch
#

@wanton tulip this is the simplest error. Did you fix it?

wanton tulip
#

Well, I have put my index.html in a folder, now the 'jinja2..' error is over.

nimble epoch
#

Need help?

wanton tulip
#

Let me look for it, I am feeling embarrassed. Thanks for wanting to help.

nimble epoch
#

Yw

#

You knew that you gotta put your index.html in a template file, didnโ€™t you?

wanton tulip
#

Omg.. smh.. I checked the sourcecode 'templating.py'.. They even commented there, with an explanation.. Thanks atleast, I am embarrassed.

#

Was just reading over it in the docs..

nimble epoch
#

Good๐Ÿ˜‰

lilac belfry
#

I have changed my domain from example.xyz to example.com finally after buying it from the owner.

Is there any way with cloudfare to redirect the old domain domain to the new one? I know of page rules but I want to preserve sub domains such as:

img.example.xyz/t.png
img.example.com/t.png

cyan violet
#

i get this with flask socketio ERR_SSL_PROTOCOL_ERROR

#

I dont have flask ssl cert but i have one setup on heroku

frank nebula
#

does anyone knows how to change the data from DRF serializer before send to the user?
"data": { "added_companies": [ { "code": "252151241", "company_data": { "id": 1, "status": "fake",

I want to retieve the list inside the added_companies and get something like this:
"data":{{code:2525.....},{code:2112....

tiny dirge
#

After a month of learning Django, i actually start building projects of mine but recently i get confused, coz everyone's talking about React and telling me to use it, so do I really need to use it while I'm working with Django/jQuery ?

vestal hound
#

After a month of learning Django, i actually start building projects of mine but recently i get confused, coz everyone's talking about React and telling me to use it, so do I really need to use it while I'm working with Django/jQuery ?
@tiny dirge you don't have to use React

#

plain jQuery will be fine

#

(depending on what you want to do)

#

does anyone knows how to change the data from DRF serializer before send to the user?
"data": { "added_companies": [ { "code": "252151241", "company_data": { "id": 1, "status": "fake",

I want to retieve the list inside the added_companies and get something like this:
"data":{{code:2525.....},{code:2112....
@frank nebula override to_representation in your serializer

topaz widget
#

Does anyone else struggle writing markup with lots of anchor tags, span elements, etc... while also maintaining a clear communication style?

#

I find the process of tagging everything takes me out of the "writer's head" mode.

warm garden
#

I have been using ruby on rails and there was a gem delayed jobs for queuing long running tasks .. is there any similar thing in flask_restful for doing that?

fringe osprey
#

I'm creating a test application using Flask on Python3.8.3, and it correctly receives my post request data, and my post request data is correctly being sent, but request.form is always empty, can someone explain why? (I'll link my code below.)

#

CODE: ```py
def WebMain(q):
from flask import Flask, request, make_response
web = Flask(name)

def GetFile(file):
    try:
        with open(file,"rb") as f:
            data = f.read()
            f.close()
            return make_response(data)
    except FileNotFoundError: return make_response("")

@web.route("/")
@web.route("/index.html")
def index(): return GetFile("index.html")

@web.route("/favicon.ico")
def favicon():
    response = GetFile("favicon.ico")
    response.mimetype = "image/x-icon"
    return response

@web.route("/background.png")
def background():
    response = GetFile("background.png")
    response.mimetype = "image/png"
    return response

@web.route("/verify.html", methods=["GET","POST"])
def verify():
    if request.method=="POST":
        print(request.form)
        return "Yes"
    else: return GetFile("verify.html")

print("Website has loaded!")
web.run()```
#

(Also the reason it's wrapped in a function is because I'm using multiprocessing.Process to run it and I'm importing it inside another script)

#

Console Output: ImmutableMultiDict([]) 127.0.0.1 - - [19/Sep/2020 12:53:04] "POST /verify.html HTTP/1.1" 200 -

#

Client command: py requests.post("http://127.0.0.1:5000/verify.html",json=[0,1,2,3])

#

(I'm only using requests.post because it's easier to test that way, in reality it's being sent by a browser)

valid sandal
#

hi

hollow inlet
#

Hello

fringe osprey
#

To whoever asked that unrelated question earlier, here's how I'd do it: py def MassDelete(s, c): if len(c): return MassDelete(s.replace(c.pop(), ""), c) else: return s

>>> MassDelete("ABCDEFGHIJ",["A","C","D","J"])
'BEFGHI'```
warped timber
#

@fringe osprey str.translate is much more efficient

#

only needs 1 loop instead of n loops

#

where n== number of chars

lethal orbit
#

I'd just do return "".join(_ for _ in s if _ not in c) or similar.

#

If c is a set instead of a list, even better.

native tide
#

I am not sure if this fits under this category its websites and database stuff but I have a wordpress website and I just wanted to know if their is a way to modify documents in mongoDB from my wordpress website through like html code or a button or something?

tepid lark
#

Wordpress is bound to mysql

cold socket
#

Hey all I have a Flask app that uses Redis for task queuing and React in the front end. I am running all in a development environment on my macbook. I really want to deploy this to a VPS on like DigitalOcean/Linode. What is the simplest/most efficient way to deploy it?

lethal orbit
#

There may be plugins for mongo with WP? I wouldn't know though, I haven't used that in years.

#

@cold socket docker-compose

tepid lark
#

Yeah docker is the way to go

native tide
#

no I check their are none unfortunately, I just prefer mongoDB as it is non SQL but...

lethal orbit
#

Then you can write your own.... or use something in python lol

cold socket
#

So I am hosting all my code on GitHub. When I need to push out an update does Docker integrate with Git some how?

outer apex
#

@fringe osprey to get JSON data from the request, you'd use request.json

lethal orbit
#

So I am hosting all my code on GitHub. When I need to push out an update does Docker integrate with Git some how?
You can use github actions to automatically build your containers, and deploy on push.

cold socket
#

So I don't have to build the docker image locally? I can just build it based off my repo?

lethal orbit
tepid lark
#

No, but you do need somewhere to store it

lethal orbit
#

You don't have to build it locally, but I do like a consistent flow, so I use docker for dev and for deployment.

tepid lark
#

github action to push to DO container registry and pull from there

lethal orbit
#

No, but you do need somewhere to store it
Not necessarily. You can just build it on the VPS and bring it up, no need to push it anywhere.

cold socket
#

Interesting, so when you start developing something in dev do you start with a container and develop in there?

tepid lark
#

yeah but that's harder to integrate with your CI

lethal orbit
#

Yeah, I do.

#

yeah but that's harder to integrate with your CI
What? How?

#

Literally the same except minus the push lol

cold socket
#

Ok good to know. I'll need to research some tutorials on containerizing Flask w/ Redis.

#

Thank you guys for the help!

lethal orbit
tepid lark
#

I hadn't considered doing actions on your VPS as part of that

#

code goes in, artifact comes out

merry geode
#

I am trying to run a flask application on Windows. I keep getting the error

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

I have tried both set FLASK_APP=main.py and $env:FLASK_APP=.\main.py, but it just refuses to run. Can anyone help

cold socket
#

@lethal orbit Thank you!

#

@merry geode I recommend using python-dotenv

warped timber
#

check if the file is actually in your cwd

merry geode
#

I am using virtualenv as of now. Does that make a difference?

warped timber
#

no

merry geode
#

check if the file is actually in your cwd
@warped timber yes, it is

cold socket
#

@merry geode Nah its different. Install it using pip install python-dotenv and then create a .env file in the root

warped timber
#

no

#

You don't need to

cold socket
#

It'll make managing your environment variables much easier

tepid lark
#

how are you starting flask

merry geode
vestal hound
#

@merry geode did you check if the variable is actually set?

fringe osprey
#

@fringe osprey to get JSON data from the request, you'd use request.json
@outer apex Thanks

vestal hound
#

like, in the first line of your script, import os; print(os.environ['FLASK_APP'])

warped timber
#

try in cmd

#

idk

merry geode
#

@vestal hound doesn't seem to have been set

#

I get a KeyError on running that command

lethal orbit
#

Try forward slashes...

#

windows is dumb

vestal hound
#

I don't really remember how to set environment vars on Windows

#

but, yeah, that's why you have a problem

merry geode
#

windows is dumb
@lethal orbit From a development perspective, totally agree

lethal orbit
#

Using \ is usually a bad idea.

merry geode
#

But then, Flask is also dumb

cold socket
lethal orbit
#

lol, yeah. I have struggled a lot with that same error even on Linux.

outer apex
#

@merry geode if main.py is in the root of the directory, you can ignore the .py extension

merry geode
#

Nope, forward slash also doesn't make a difference

outer apex
#

on Linux, it's export FLASK_APP=main

cold socket
#

I'm telling you creating that .env file in the root will help you with your headaches

outer apex
#

I can't remember what the export equivalent is for Windows

merry geode
#

The windows equivalent is set

#

But it's not working

#

I'll try dotenv

cold socket
vestal hound
#

The windows equivalent is set
@merry geode probably syntax is wrong

cold socket
#

Are you on Windows 10 btw?

merry geode
#

@merry geode probably syntax is wrong
@vestal hound not getting any errors on running that command. It runs fine.
Also, I found it on a Flask tutorial itself

#

@cold socket Yes, Windows 10.
So I have .env file and I have put FLASK_APP=main.py in it. Now how to I use it

vestal hound
#

@vestal hound not getting any errors on running that command. It runs fine.
Also, I found it on a Flask tutorial itself
@merry geode in the sense that it's not setting the right thing

merry geode
#

OK, got it. It ran, thank god. I needed to write python -m flask run instead of just flask run.

#

Thanks!

cold socket
#

@merry geode I usually put these two lines in there FLASK_APP=app.py FLASK_ENV=development

#

And flask run always works

merry geode
#

BTW, I was trying to use FastAPI at first. But some library called orjson just refused to get installed.
First it threw some error which got resolved by switching to Python 64-bit. Then it threw another error which should have gotten resolved by installing rustup, but got resolved only after selecting the nightly build of cargo or whatever. But then it threw a new error, at which point I just got frustrated and switched to Flask

cold socket
#

Also I believe with Windows when you use "set" that only stores the environment variable temporarily. So if you start a new session you have to set it again.

merry geode
#

And flask run always works
@cold socket I think there's some issue with my installation where flask run tries to run it with 32-bit Python and hence fails, but when I put python -m flask run, it finds the right interpreter

cold socket
#

@merry geode That's unfortunate. I was actually looking to make the transition to FastAPI but ill wait till it matures a bit more.

merry geode
#

Oh, no. Actually, after putting the .env file, even flask run is working. That's great. Thanks @cold socket

cold socket
#

@merry geode That's interesting. Yeah I stopped using Windows completely since I switched to my mac. But glad to hear its working.

warped timber
#

what about the thing its built on?

#

I think starlette?

merry geode
#

Actually, I had run FastAPI in the past myself. But at that time (actually, just 4-5 months ago) I was very new to web dev and Django just felt easier to get started with. I was not familiar enough to set up the entire project the way FastAPI and Flask require.
Now that I understand things a lot better, I thought I'll try it out, but for some reason now I'm not able to run FastAPI. Don't know what changed in that time.

#

I think starlette?
@warped timber hadn't heard of it. might give it a try

barren stratus
marsh canyon
#

@barren stratus one thing to do is verify if the URL is legit before shortening it

gleaming thunder
#

Right so, what's your current set up right now?

#

Cool, have you set up Gunicorn/uWSGI yet?

#

It is, yes, though you'll have to set up those two things and configure Apache first

#

So basically, you know how like, Flask comes with this development server that basically allows you to check out what you're currently working on locally?

#

Basically you'd want to configure Apache so that domain.com/foo routes into your Flask app instead

#

Unfortunately I've only actually used nginx for my Django app so I'm not really familiar with the configuration

#

Right, that's as far as I can go in terms of Apache, again, I'm not as familiar with it as I'm familiar with nginx

#

You could try routing

lethal orbit
#

You should use mod_wsgi for Apache

novel pawn
#

Would I need a vps?

#

Or just cpanel

lethal orbit
#

I haven't used apache in a while, but maybe?

#

If you ask me specific questions

novel pawn
#

:V

#

hullo?

lethal orbit
#

No, no. I mean I am running a website (just html, css, php, javascript files) using Apache. How can i run a flask app on the same server for the same domain but like domain.com should take to my normal website and domain.com/flask should lead to flask app?
@native tide you can just follow that example. Put your flask directory in that Directory directive.

novel pawn
lethal orbit
#

Nope?

#

That's what Directory directives are for ๐Ÿ˜„

#

If your site is at /var/www and your flask app is /var/www/flask, you can just add a Directory /var/www/flask section

#

Yeah

novel pawn
#

Could anyone help

lethal orbit
#

Well then, use /var/www/domain.com/flaskapp

#

No, you just need to enable mod_wsgi and configure it.

versed python
#

Could anyone help
@novel pawn clone that website, then pip install -r requirements.txt. Then you can execute the start.sh script given

novel pawn
#

Would I need a VPS or is cPanel fine

versed python
#

you can do it in your local computer, why would you need a vps

novel pawn
#

But I wanna hjost it on my site

#

host*

versed python
#

Could anyone help
@novel pawn Look at the start.sh script. you will probably need to add a ngnix service for it.

novel pawn
#

Aw man

#

Thanks

versed python
#

Django: How do I unlink images that were uploaded to my disk? Suppose I delete an object of PostImage, how do I delete the actual image.png that would be stored in the disk?

#

Do I have to do that manually?

lethal orbit
#

Note that when a model is deleted, related files are not deleted. If you need to cleanup orphaned files, youโ€™ll need to handle it yourself (for instance, with a custom management command that can be run manually or scheduled to run periodically via e.g. cron).

#

Maybe handle it in the pre_delete signal?

versed python
#

That kinda sucks

#

but I see how that would be useful

#

Maybe I will have to write a py script to recurse over the directories and delete unlinked files

lethal orbit
#

It imports the variable app from the file named yourapplication.py and renames it to application

rancid lintel
#

should i design the api first or plan the react front end before that?

lethal orbit
#

Iterate and do both at once ๐Ÿ˜„

#

I usually just add a basic page, with fake data on the front-end. Then add an API call.

rancid lintel
#

Iterate and do both at once ๐Ÿ˜„
@lethal orbit expected easier answer lol

lethal orbit
#

Hook up the front-end to the back-end, then work on another feature.

#

You don't need to spend too much time overdesigning an API ahead of time.

#

Sometimes I do it the other way around.

#

You can just call the API using curl for REST, or graphiql for GraphQL. It really doesn't matter.

#

(yes, there are tons of other options I didn't bother listing).

rancid lintel
#

@lethal orbit nice man thanks.

lethal orbit
#

@lethal orbit In my var/www/domain.com/flaskapp what files should I have for example for a hellp world program?
@native tide I don't really use Flask, and never have with apache, but I think you need one file for your app, and one .wsgi file.

lethal orbit
#

Are you on the same machine as Flask?

#

127.0.0.1 is localhost

#

Then you can't use Firefox.

#

127.0.0.1 is your machine.

#

You can use curl on the server.

#

curl http://locahost:5000 should work, if you open a new SSH section

#

No, it's not bound to the public IP

#

On the loopback interface ๐Ÿ˜„

#

* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

#

flask run --host=0.0.0.0

#

or use app.run(host= '0.0.0.0')

#

You need to bind to the public IP.

#

0.0.0.0 binds to all available interfaces.

tacit comet
#

any advice format docuement tool for django html

lethal orbit
#

Yes

#

If you run flask locally, localhost should work.

#

add ``` before and after``` your code... (to make it readable on discord)

#

The rest looks fine.... though I think you are missing a () in app.run()

astral musk
#

can anyone tell me why my <script type="text/javascript" src="{{ url_for('static', filename='jquery-3.5.1.min.js') }}"></script> only works if I have it in my template that uses the script but wont work if i have it in the layout.html which is extended in the same page?

#

do the scripts have to be loaded in a specific order?

#

wait, now it suddenly works both ways.. wtf nvm

#

no, it's back again

#

if I put it in the end of layout.html, jquery wont work