#web-development

2 messages Β· Page 73 of 1

nova escarp
#

Hmm good idea. Would it be possible for it to automatically add an instance to that class based off of what the user inputs in the other class?

grave anchor
#

I have just started to learn programming...
can someone help me with giving me information about the job market
is that possible to find a remote or freelance job in another country ?'

#

is this the right channel for this type of help ?

brave karma
#

so i have a website and discord bot using the same database, and lets say i want the discord bot to cache anytime it gets or updates a document in the db. How do I make it so whenever the website makes changes to the db, it update's the bot's cache as well? Btw the bot's cache is currently bot.db.guilds_info (a dictionary). The database I'm using is MongoDB.

#

not really 100% web dev related but i think it fits more to this channel than #discord-bots

glass sandal
#

So you have an API right?

brave karma
#

how does that fix the issue tho

#

the bot has to query the website not the other way around

#

right

#

i want it so when the website changes something it lets the bot know

glass sandal
#

So it uses an API

#

Oh

#

So you can check every like 5 seconds or 1 minute?

#

Like requests.get or urllib

cold anchor
#

your website and bot should share the cache and whenever the API gets new data, it should bust the cache so the bot has to get the new data

brave karma
#

also btw the reason im caching stuff in the bot is so i don't have to request the DB on every message that someone sends

flint breach
#

Basically what rdbaker said

brave karma
#

how would it share the cache if they're run separately

flint breach
#

redis perhaps

#

Or a different approach is needed

brave karma
#

i mean they're already shared in mongodb

#

but i just don't want to request mongodb on every single message

flint breach
#

You need somekind of mechanism of invalidating the bots cache

distant trout
#

can someone help me check if my flask website login/registration works? I just deployed it to heroku... U can use fake logins if u want

flint breach
#

For whenever the website updates the db

distant trout
#

its a simple QnA website

glass sandal
#

So you want to update it on message and not sending a request when EVERY message comes?

#

@distant trout Can't you test it? Like a logout functionality or so?

brave karma
#

nothings being updated on_message, only fetched

glass sandal
#

Oh I see

brave karma
#

but the problem is when the website updates the database, the bot's cache is outdated, but the bot doesnt know that

distant trout
#

hmm... it works fine for me.

#

i think it should be working fine for others

flint breach
#

Yea, some kind of signaling would be ideal

#

A shared cache would be the simplest solution

glass sandal
#

@distant trout Yep. Until you hold your data in flask session . Or if you are using flask_login then I'll assure you it'll work

distant trout
#

Yeah, i am using flask-login πŸ˜„

glass sandal
#

Then it must work . Or it'll give an error or something

#

And you can view if it gave an error by running heroku logs --tail

#

If you didn't know

distant trout
#

Yeah, it hasnt given me any error. Everything seems to be working fine

#

I had problem with gunicorn at first but now its fixed

glass sandal
#

Oh

#

So then I guess .... No problems

distant trout
#

πŸ˜„ awesome, thanks

glass sandal
#

XD I didn't do anything lol

distant trout
#

u just reassured me πŸ˜„

glass sandal
#

XD lol

flint breach
#

but the problem is when the website updates the database, the bot's cache is outdated, but the bot doesnt know that
@brave karma perhaps set a short countdown on cache invalidation

#

Depends how often the db is updated

brave karma
#

yeah that seems like the "best" solution i could think of

flint breach
#

Definitely the simplest

zealous siren
#

I'd say some from of Redis cache the bot checks

#

when website updates, it just updates Redis cache

#

and Redis cache could be a simple as <user>:<true/false> for been updated

cold anchor
#

alternatively, you could skip using a cache at all, databases are generally made for fast reads and cacheing should be used as a strategy when it's expensive to read from the db

flint breach
#

Im gueesing hes using a cache for a reason though

cold anchor
#

sure, everybody uses a cache for a reason- @brave karma have you seen such a hit in performance that you'd be nervous using your both without a cache? What's the 99th percentile API response time?

flint breach
#

Then again, a production cache like redis will do you better

zealous siren
#

Does MongoDB cache?

#

I haven't used it

#

I would assume so

cold anchor
#

generally all databases do, but yeah, I'm pretty sure mongo allows you to specify caching the results of a query

brave karma
#

not atm i dont think, just thinking long-term :p

magic forge
#

Has anyone here made a website using file manager in cpanel?

cold anchor
#

implementing and managing a cache is usually expensive enough that it's not needed until it's really needed (e.g. 1s response times from the API)

flint breach
#

True ^

brave karma
#

true

cold anchor
#

and by "expensive" I mean having the think of and implement caching strategy problems that you're currently asking about

brave karma
#

if anything ill just make cache disappear once or twice a minute or something , definitely not anything too long

#

ill think about it

zealous siren
#

sometimes it's worth learning new just for fun even if it's not required

acoustic oyster
#

@magic forge yes

#

a long time ago though

magic forge
#

I already got my webasite lmao

#

I didn't even need help since the website already worked

#

I just didn't type www

#

Look at the favicon and name

acoustic oyster
#

haha, I figured, thought I'd make sure though

#

Idk if this is because you are still working on it, but none of the styling/images/etc are there

#

also: I need like 33% of a circle 3d modeled at like 3mm for 3d print, how much? haha

#

Also, last comment: I see someone made the blender guru donut πŸ˜‰

rancid storm
#

Anyone got the js discord invite, if so dm me, its for a friend πŸ™‚

magic forge
#

@acoustic oyster Yea I'ma modeler

acoustic oyster
#

awesome

#

I dabble, just for 3d printing

fallow fjord
#

Hello,
I am working on creating a backend script for social media blog letter(like news letter) and email it to myself daily.
I want to gather top 10 or 20 posts I see in my Overview section of Reddit and send email them to myself. I am working with Praw (Reddit API). I tried to find some function or method which will give me these overviews. However I didn't find anything. I checked dir(redditor(username)) or dir(user.me()) to see if anything works but didn't find it.
Does anyone know how I can get this working?
Thank you

marble zephyr
#

I need to write a fairly long html code inside inside a var, in javascript. When I hit enter inside the quotes they return a syntax error when I run the code.
Example:
var item = '
<div id="data-row-${i}" class="task-wrapper flex-wrapper"><div style="flex:7">
<span class="title">${list[i].title}</span>
</div>
<div style="flex:1">
<button class="btn btn-sm btn-outline-info edit">Edit </button>
</div>
<div style="flex:1">
<button class="btn btn-sm btn-outline-dark delete">-</button>
</div>
</div>
'
Returns a syntax error because I entered a newline. How do I fix this?

#

Im using atom as my text editor

keen lily
#

@magic forge cool website

#

did u buy a domain

#

or how did u get the .com

magic forge
#

I swear its so cheap

winged island
#

hi i have a question about wtforms. this doesn't work: (i'll send the form code in the next message)

#

what am i doing wrong?

azure saddle
#

hey everyone
I just wanted to ask that is it better to use django than using flask to make websites in python

#

well I don't know anything about django

faint dew
#

I just asked my buddy who's into web dev and he said he used flask when he started and then transitioned to django

final geode
#

sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:sqllite?

final geode
#

Found my problem

#

SQLITE not SQLLITE

azure saddle
#

I just asked my buddy who's into web dev and he said he used flask when he started and then transitioned to django
@faint dew ohk thanks bro

final geode
#

Why is my django stuck on watching for file changes with statreloader?

atomic marsh
#

@azure saddle you can check out the django official tutorial on the website, to see if you like it.

#

How are you running it?

#

@native tide check out jsonwebtoken. It's for JS, but you'll find something similar for flask

atomic marsh
#

These are called parameters

#

Are you making the request or handling it?

azure saddle
#

How are you running it?
@atomic marsh what??

atomic marsh
#

That was for mechonis, @azure saddle

azure saddle
#

ohkkk

sullen wagon
#

I hope this is the place for Django questions. Suppose I make a model, migrate it and then add data to it using shell. I then change column names/data types and migrate again. When use the shell again I get an error saying that the data previously there doesnt follow the new schema changes. What's the best way to deal with this?

Should we drop the entire table and start over?

flint breach
#

change column names/types in what way

#

changing column names shouldn't be a problem

sullen wagon
#

I changed column type from charField to IntegerField

flint breach
#

if you don't have any important data, you could just drop the table and repeat the migrations

#

but of course, the problems of the world are usually not this easily solvable

#

you could for example, add another column, runing a data migration to iterate over all objects, and write to the new column, and then finaly delete the old column

#

to be honest, im not sure what the preffered method is

#

what error does it bring up

glass sandal
#

@azure saddle The bigger the project gets , the better fask is

#

Since it has much more flexiblity

#

And Django is black magic

flint breach
#

disagree tbh

glass sandal
#

If you want to get a job or freelance , use Django

flint breach
#

flask is perfect for small/mid sized projects

glass sandal
#

But when the project gets big , it's better to use Flask

#

Why?

#

Cause

#

Flask has much more flexiblity than django

#

And you understand your code

#

But

#

Django has much more less flexiblity

#

And you don't understand your code deeply

flint breach
#

anything you need to do, you can do tbh

glass sandal
#

But Flexiblity is where flask shines

flint breach
#

you don't want to write every part of your codebase

#

django has third party apps

glass sandal
#

But you don't want to write black magic code either

flint breach
#

"black magic code"?

glass sandal
#

The code you don't understand ... basically Django

#

Like you don't understand your code deeply

#

And that means you have to review your code every once in a while so you can just get what it does (when the site gets big)

flint breach
#

as the complexity grows, you won't even remember half the code anyway

#

abstraction is good

#

django is tried and tested, you don't need to understand how the low level bits work, to make a good project

glass sandal
#

I said , Flask is better for YOUR projects and websites made by a group (even big), but django is good if you want a job in a company or freelance

#

We are all biased , it's undeniable

#

Use everything you are comfortable with

#

I am comfortable with Flask , and I use Flask . You are comfortable using Django , and you use Django

#

I mean , I learned Django first , then I went to Flask

flint breach
#

you can say that, but specific tools fit with specific tasks, some better then others

glass sandal
#

You can make same websites using both , can't you?

flint breach
#

you can make websites with C if you want to

glass sandal
#

They have all features you'll need . Either with libraries , or by themselves

#

I myself , enjoy using Flask more . I like to understand all my code . And Django is just opposite of what I like/need

#

Maybe if I was to freelance , I woulde use Django

#

But if it was gonna be my website

#

I'd rather Flask

flint breach
#

fair enough

azure saddle
#

well thanks @glass sandal and @flint breach for now I'll go with flask as my project is not much big

halcyon oriole
#

Hi everyone, I'm currently having a small problem with bs4. I'm trying to extract the text from a span but it has parenthesis around it and it seems to be an issue.
here is the html code:

<div class="matchTeamScore">
    <span class="currentMapScore" data-livescore-current-map-score="" data-livescore-team="10371"></span>
    <span class="mapScore"> (
        <span data-livescore-maps-won-for="" data-livescore-team="10371">0</span>)
    </span>
</div>

here is my python code :

.find('div', {"class": "matchTeamScore"}).find('span', {"class": "mapScore"}).find("span").text
#

the result is just an empty string (i want to get the 0...)

flint breach
#

because there's another span inside that span

#
soup.find('div', {'class': 'matchTeamScore'}).findAll('span')[1]
#

of course, the specific case of geting the first nested span would be prefered

halcyon oriole
#

it works thx @flint breach

lucid vine
#

How do I get a flask response to return a json?

#
endpoints = {
    "up": "/up"
}

@app.route('/', methods=["GET", "PUT", "POST", "DELETE"])
def home():
    if request.method == "GET":
        return  Response(endpoints, status=200, mimetype='application/json')
neon needle
#

@neon needle I can πŸ™‚
@foggy geyser
Come dm pls

flint breach
#

flask probably has some sort of

#

JSONResponse object

#

or straight up, json.dumps() the dict and modify the mimetype

lucid vine
#

got it working with json.dumps() thx

#

it is my first dabble with API's and web development

nova crest
#

Hello guys,

I have made a Flask web app which runs fine locally, but it doesn't work on Heroku. On heroku, it says "NameError: APIservice not defined".

APIservice gets defined in the 'start' view:

@app.route('/start')
def start_teatime(): # Checks auth & builds calendar API (APIservice)
    print('stat_teatime trigger')

    global APIservice

    if 'credentials' not in session:
        return redirect('authorize')

  # Load credentials from the session.
    credentials = google.oauth2.credentials.Credentials(
        **session['credentials'])

    APIservice = googleapiclient.discovery.build(
        API_SERVICE_NAME, API_VERSION, credentials=credentials)


    return redirect(url_for('user_input'))

On the user_input view, APIservice is used. Locally, this works fine. On heroku, it throws a NameError and claims APIservice is not defined.

Does anyone have an idea why this is happening?

nova crest
#

I found a workaround. I just put all the code above in the user_input, since it wasn't used in the start view anyway

#

or well, I say that

#

but it now throws the same error in another part of the script

#

Why is heroku resetting the APIservice variable...

glass sandal
#

Cause heroku resets your app every day

#

And if you want to save something , it has to be either in the database , or in a file

#

OR as an envronment variable

#

Like it re-runs it

late stone
#

how do you post blocks of code in this chat like the one above

#

?

glass sandal
#

wdym by blocks of code?

#

Oh

#

like :

print("this?")
#

Do a ```
‍‍‍‍‍‍ `py

and close with ```
` ` `
late stone
#

py print("that")

#

with colors and shit

glass sandal
#
` ` `py
#

Not with a space

#

And write your stuff the next line

late stone
#
print("sjjf") 
#

got ya

glass sandal
#

nice

#

But JAVA?

late stone
#

ok so i have a question related to models in django

glass sandal
#

aaa ok ask

late stone
#

so I have this app called " hr_user" it already has its views func to create a new user and all that. And i have a model name Employee. How do I create an employee object under the user that is logged in?

#

models.py ```py
class Employee(models.Model):
#attributes
hr_agency_emp = models.ForeignKey(User, # this will reference the employees created under the hr company
on_delete=models.CASCADE, # so confusion can be avoided at login.
)
name = models.CharField(max_length=20)
age = models.CharField(max_length=2)
department = models.CharField(max_length=25)
mail = models.CharField(max_length=50)
date_posted = models.DateTimeField(default=timezone.now)
employe_id = models.IntegerField()

class Meta:
    verbose_name = 'employee'
    verbose_name_plural = 'employees'

def __str__(self):
    return self.name
```
#

views.py ```py

Create your views here.

@login_required
def dashboard(request):
context = {}
employee = Employee.objects.all()
context['employee'] = employee # once the hr user log in, the hr user
# will be able to see the employees on the DB
return render( request, 'user_hr/dashboard.html', context)

def logout_view(request):
logout(request)
return redirect("login")

def register(request):
if request.method == "GET":

    context = { 'form' : UserRegistrationForm }
    
    return render(request, "registration/register.html", context)

elif request.method == "POST":
    form = UserRegistrationForm(request.POST)
    
    if form.is_valid():
        user = form.save() #save/create user in the database
        user = form.cleaned_data.get('username')
        
        messages.success(request, f'Account created for {user}!')
                                # if user was created successfully then,
        return redirect('login')    # take client to the loginpage
obtuse garden
#

hey i am new to kivy-python , so can any one guide me...please dm as it would be make a lot easier for me to create my first app

late stone
#

so i tried making migration and this popped up: Please select a fix:

  1. Provide a one-off default now (will be set on all existing rows with a null value for this column)
  2. Quit, and let me add a default in models.py
dapper tusk
#

you added a column which was not allowed null and django needs to figure out what to add to that column for existing rows

late stone
#

oh i see, how do i fix it?

#

im gonna go ahead and select one, tbh i dont know what the heck im doing

static wind
#

hey all, i'm using flask to process data from a post request from ajax in JS script, how do i process lists?
i'm sending the list like this:
weblogs: automodWeblogs where automodWeblogs is an array of JSON objects (because this is in the JS code)
i'm processing the data sent by using request.form but i've also tried request.form.to_dict().
Whenever I print out the data i receive, it prints in a form like this:

'weblogs[0][user]': ['MrHouck#6969'], 'weblogs[0][time]': ['Sat, 25 Jul 2020 17:36:29 '], 'weblogs[0][action]': ['automod.bannedWord.remove'], 'weblogs[1][user]': ['MrHouck#6969'], 'weblogs[1][time]': ['Sat, 25 Jul 2020 17:36:29 '], 'weblogs[1][action]': ['automod.bannedWord.remove']

How do I fix this?

glass sandal
#

@obtuse garden This channel is not suited for that topic

stray sorrel
#

Hello, so I am using django to make a website for my client. And I am pretty new to Django, so I wanted to ask a question. My website is getting a date.now and converting it into hours and saving it on the Postgres database. I would like to make a sum of those numbers and then send it back to the database. And I wanted to ask about in which file I should put the python code that I will be making. Thank you for your help guys.

glass sandal
#

@stray sorrel

stray sorrel
#

So that's like a main file for the type of code I am making right now?

#

@glass sandal

glass sandal
#

Django and flask work like this :
When client enters a URL , a specific Python code will run . And it could return templates/HTML files which are website pages if you are not familiar

#

And views.py is where you make the functions you want to run when someone enters a specific URL

#

But keep that in mind : Url's should be defined in urls.py

#

And if you have an app , then you'll need to make one for it

stray sorrel
#

Oh, so I will have to have an app for each functionality and then I can link the button to a certain url which will then run the function.

glass sandal
#

Just go through the documentation or Youtube tutorial

stray sorrel
#

I already did a course.

#

I just wanted to make sure πŸ˜„

glass sandal
#

Oh

#

And apps are basically mini-projects

#

Like when you create a project , you'll have an app by default

stray sorrel
#

Yeah

#

I already have one app πŸ˜„

glass sandal
#

And that's your app then

stray sorrel
#

I have two apps, the default one and another one I made.

glass sandal
#

But you can do everything in one app

#

Unless your project gets big

#

And you want to organize it

#

Then you'll better have an app for accounting (signup , signin) , pages (blog , tutorial etc.) and...

#

But I myself do all in one app

stray sorrel
#

Ah, that's cool.

glass sandal
#

Since I made no big projects πŸ˜…

#

Or not what I'll call a "BIG" project

stray sorrel
#

Could you please show me how the function linking works, so I can make sure I know how to do it.

#

As this is my first project alone without anyone else looking and giving me help.

glass sandal
#

urls.py must have a line defining urlpatterns

stray sorrel
#

I have it I think.

glass sandal
#

And urlpatterns is where are your urls will be defined

#

In an array

#

And if you wanna add new urls , first make sure you imported path from django.urls

#

Then add a line like this :

urlpatterns = [
  path("urlPath/",functionToRun)
]
#

And there is an optional name key argument

#

That I never ue

stray sorrel
glass sandal
#

use*

#

Oh so now in time tracker app's urls.py you can add a path

stray sorrel
#

That's to html I think.

glass sandal
#

Ummm?

#

I mean , you define paths in urls.py

stray sorrel
#

Oh

#

Yeah

glass sandal
stray sorrel
#

Oh I was talking about returning html in views.py.

glass sandal
#

using django.shortcut's render

#

return render("file.html")
and you must've defined your template's path in settings.py or it will give an error

stray sorrel
#

Okay, I will keep that in mind.

#

And if someone presses a button on a website, which will send the data to the website. It's like a login form and you will be adding the users through the django admin area.

glass sandal
#

Oh

#

So you have a form

stray sorrel
#

It's to track when employees enter

#

so they will enter an id and submit

glass sandal
#

And if it posts the data , you need to add a {% csrf_token %} line in form tho

stray sorrel
#

And it will log the time when they submitted it.

#

Yeah, that's for security I think.

glass sandal
#

Yep

stray sorrel
#

I am not quite sure how to like link the code that is getting those two times and calculating the amount of hours they were in office from it.

#

I have the python code nearly done outside of django.

glass sandal
stray sorrel
#

As I am still awaiting html from a colleague.

#

Could you send me an example on how to apply it (just an example.) I would really appreciate it.

glass sandal
#

Ummm i mean like :

#this is a code not in django
user_logged_in = False
if signed_in and username == username_entered:
  user_logged_in = True
  time_logged_in = time

#So now you want to apply this in Django :
#Views.py
def login(req):
  if req.user.is_authenticated:
    User.objects.filter(username=req.POST['username']).time = time #Replace this with current time

#Urls.py
urlpatterns = [
  path("login/",views.login)
]
stray sorrel
#

Wow

glass sandal
#

@stray sorrel

#

Yep

stray sorrel
#

It's completely different code ;D

glass sandal
#

XD maybe

stray sorrel
#

like the syntax

#

But I understand.

glass sandal
#

But this is the case with the default user login system with django

#

And it does not have a time attribute

#

So you have to make a login check with your model

#

And it's not that tricky

#

You just need to check the session

stray sorrel
#

I was thinking that it would be cool to track the time of when the button was pressed

#

Because now what we're thinking is that we would let our employees enter their id, and they will simply press a button

#

and the time would send automatically, or we can have them click it themselves.

#

But I would put that on the front-end, not the django admin area.

#

That can be used by managers to see how many hours each employee had.

#

I already have the models ready.

glass sandal
#

So you have to only apply the code tp Django

#

And do the template jobs

stray sorrel
#

Yeah

glass sandal
#

So when your friend sends them , you'll be done

stray sorrel
#

Technically yeah.

#

And thank you so much for your help πŸ™‚

glass sandal
#

You mean changing an object?

#

And np

#

You have to object.save()

#

After you edit attributes

stray sorrel
#

Object.save and pass out a value?

glass sandal
#

Nono

#

Like

object.username = "Something"
object.save()
stray sorrel
#

do you need to pass the name of the object

glass sandal
#

You have to find the object

#

Model.objects.filter(username="Something")
will find an object with a username something

stray sorrel
#

Is it all listed on the django project website, so I can check some more details if I am not sure?

glass sandal
#

I guess so?

#

The API docs has everything

stray sorrel
#

Because thanks to you I am now more sure about how to do it πŸ™‚

#

Oh epic!

glass sandal
#

And np

stray sorrel
#

So if I understand correctly

#

can we make a user login using an id.

#

without password

glass sandal
#

Yes

#

model.objects.filter(id=1281398)

#

If it's None , it means it is not an object

stray sorrel
#

So we can do an error message if that happens using an if statement.

glass sandal
#

Yeah

stray sorrel
#

Thank you so much for your help, I really appreciate it πŸ™‚ I will go take a look at the documentation to get a better understanding.

glass sandal
#

Ah np

stray sorrel
#

Have a great day!

glass sandal
#

Hope you finish your project tho

#

And you too!

stray sorrel
#

I think I can do it, as I was making C# apps before. This is just a bit different πŸ˜„

glass sandal
#

Oh I see

stray sorrel
#

different language and different environment.

glass sandal
#

XD yeah

stray sorrel
#

But thank you really.

glass sandal
#

Nah np

#

I myself struggled while I was learning Django

#

And you know , you have experience on C# . Back then I only knew C++ and JS and Python

#

And you are not struggling so much as I see . And it's great

#

GL on your journey th

#

tho*

stray sorrel
#

Oh, thanks πŸ™‚

#

I appreciate the feedback and your help again.

#

Good luck on your journey as well!

glass sandal
#

Thanks! And why are you thanking so much? That's a nice of you tho! Like everyone I help thanks me once , and I don't have problem with that tho

stray sorrel
#

I am just so grateful that you helped me out.

#

As I was struggling today.

#

Trying to figure it out.

glass sandal
#

Oh np

olive egret
quick cargo
#

template does not exist

olive egret
#

how do I fix that?

glass sandal
#

You don't have that html file

quick cargo
#

i dont know Django's template layout :/ but i imagine you dont have the file in the right place

glass sandal
#

@olive egret

olive egret
#

no

glass sandal
#

Oof

#

That's why

olive egret
#

I'll do that

glass sandal
#

kk do it . it'll work

#

@olive egret Did it work?

modest scaffold
#

For djangos template system when using a variable when do you use a . and when do use a | when trying to access properties of that variable

#

e.g. {{name.count}} to get the length of the name , {{job|pluralize:",s"}} to add a nothing or an s when there is more than one job

olive egret
#

@glass sandal no it didn't work

candid quiver
#

hi all, what would be a better content-type (considering both would work) to post object with text fields, image and array of objects, application/json and raw data or multipart/form-data? Or maybe something else?

#

atm I'm using multipart/form-data and parser_classes = (MultiPartParser, FormParser) in my viewset and while it uploads data and image fine I can't upload the array of objects

native tide
#

evenin' all! i'm attempting to create a login page for a CMS i'm making and i'm having trouble understanding how to pull a hash from the db, and compare it to the pw input by the user from the login form. can't seem to wrap my head around the step by step in pulling the hash out, comparing it to the input, and then saying yes/no for logging in based on if it's correct or not. using py3.8, tornado and argon2id. if i should add more to my question, pls let me know. c:

crisp saddle
#

you hash the pw entered by the user using the same hashing algorithm as the hash you have stored in the db was generated with

#

if the two hashes match the pw is correct @native tide

native tide
#

ah i see, that makes sense! i'll give that a shot, thank you!!~

keen lily
#

@olive egret

#

create a new folder

#

name it whatever

#

put ['name of what the folder is']

#

@stray sorrel you're going to have to learn models and forms for django

stray sorrel
#

I already learned how models work, I was just making sure I understand the topic correctly πŸ™‚

hollow glacier
#

What is the best way to Limit what kind of url goes into a URLField? Like I only want Spotify playlist urls to be allowed. Would I use regex and create my own validator or would i look for certain keywords when saving the model?

opal robin
#

hello i try to run server in one of my projects and command in terminal runs fine but it doesn' execute anything

ocean sigil
#

Hi everyone, what has been the most comport css framework for you when you worked with templates ?

unreal atlas
#

im trying to do somethink cool with my life and not be depresd like some peapole with jobs that they work for and i wanna find someone that cloud like invest some money and we cloud make a buisness and like i would work for free cuaze im young and i stzarted to do somethink soo i started like this:
-first i started game development with c# for a month but then i quit becauze i didnt like it
-second i did Html,Css,Java script
-then i did python and now im doing Copywriting
thats perfect for selling and online sellling and yeah

proud igloo
#

hey guys is it bad practice to serve static files in a docker continer for django?

quick cargo
#

ehhh yes and no

#

you shouldnt be serving static files from a python http server

#

thats the job for the Production server like Nginx todo to relieve load

proud igloo
#

How come you shouldn't?

quick cargo
#

load

#

Python is pretty slow when it comes to http server speed

#

and if you imagine each page has a set of static files each request can easily turn into 5 or more static file calls

#

which will just eat your server up

proud igloo
#

ahh interesting

#

do you know why it is slow?

#

but it is okay with dynamic pages? or it just doesn't matter as much?

quick cargo
#

its just because Python is interpreted

#

It is always going to be slower than Compiled langs

proud igloo
#

yeah fair enough

#

so what would you reccomend I do?

#

upload them to a CDN?

#

or have a static file nginx container?

flint breach
#

tbh, it doesn't matter that much

#

you could use

quick cargo
#

you normally serve static files with Nginx or apache or what ever prod server youre using to deploy with

flint breach
#

but yea in general what ^ said, delegate the handling to some other entity

#

either a proxy like apache/nginx or to a cdn

proud igloo
#

so don't use whitenoise?

#

it looks nice and easy πŸ™‚

#

the most painful bit of this is

flint breach
#

(whitenoise) It’s designed to work nicely with a CDN for high-traffic sites so you don’t have to sacrifice performance to benefit from simplicity.

proud igloo
#

needing to run collectstatic in my CI

#

setting up an nginx container is very easy

flint breach
#

collectstatic is just one command, specially in a CI isn't really a hassle, is it?

proud igloo
#

well when do I run it?

#

make sure I run it every time I push with some githook?

#

painful

#

ask the CI to write the output to github?

flint breach
#

how is it painful, it's automized?

proud igloo
#

bit messy

dapper tusk
#

you can run it before starting the server, it is really fast when it has to do no changes

proud igloo
#

but the server and the nginx container are seperate

#

one Dockerfile runs manage.py the other nginx I just need to connect a volume

#
FROM python:3.8-slim
COPY . .
RUN pip install -r requirements.txt
RUN apt update && apt install -y curl
HEALTHCHECK CMD curl --fail http://localhost:8000/ || exit 1
CMD [ "python", "./manage.py", "runserver", "0.0.0.0:8000"]
#

I just have this currently

quick cargo
#

docker compose the badboy

#

btw do not use the development server as a actual server

#

that development server should never be used for serving files to actual users

flint breach
#

gunicorn or alike are recommended

proud igloo
quick cargo
#

yeah

proud igloo
#

sorry new to django πŸ™‚

#

ahh shit

#

okay

quick cargo
#

runserver is just a dev server

#

not a prod grade server

proud igloo
#

was worried this was going to bite me in the ass

#

okay so what should I be doing sorry?

#

and why is this bad?

flint breach
#

because it's not meant for being used in production

quick cargo
#

it has little secuirty and optimisations

flint breach
#

security and performance wise

proud igloo
#

what does?

#

gunicorn?

flint breach
#

the development server shipped with django itself

#

runserver launches an instance of a django development server

#

not meant to be used in production

#

look into gunicorn, or some other wsgi compliant server

proud igloo
#

okay sweet thank you

#

do you have any good tutorials?

#

man this is brilliant

#

literally answered everything we talked about

#

the trick seems to run collectstatic in the django container

#

and then create a volume to that static folder that is also a volume to the nginx container!

flint breach
#

basically you have to share the collected files with the proxy yea

proud igloo
#

is collectstatic ran automatically?

#

bit confused

flint breach
#

You have a ci, just run it in that step for production

#

Thats why you keep 2 enviorments (or more), one where you develop and test things out using the local server, where changes are made fast yet not meant for production, and a production enviorment

late fjord
#

HI I have a problem with groups in django

#

can anybody help

#

me

flint breach
#

just ask

#

don't ask if you can ask

late fjord
#

Imagine I have a user who is in the group "free" I wanna make a condition that checks if the user is "free" he sees in the home page "upgrade to premium" but if he's premium he doesn't see it

flint breach
#

so basically you just need a simple check if he exists in the group

late fjord
#

he exists in the group because when he signs up he will directly be in the group free

flint breach
#
group_members = Group.objects.get(name="free").user_set.all()

and then if
if user in group_members show premium etc

late fjord
#

thanks, I'll try

flint breach
#

basically you just need to get the group you want, get the members of that group, and check if the group contains him as a member

#

perhaps not the most efficient though

#

if user.groups.filter(name=['free']).exists() user.groups.filter(name='free').exists() perhaps something like this, so you don't check for all members

late fjord
#

thanks

#

got it

#

how long have you been using django

#

in the name=['free'] why do we put brackets

#

I mean these []

#

is it because we can put a list and it will filter them

flint breach
#

parodn, it's without square brackets

#

you can put user.groups.filter(name__in=['free', 'some_other_group']) that works like that though which is basically

groups = ['group1', 'group2']
for group in member.groups:
  if group in groups:
    ...
#

i've been using django for about a year now

#

still preety clueless, don't worry, django is massive πŸ˜›

late fjord
#

thank you

tight grotto
#

=====fixed======
so

#

how do i make it like stick till the end

flint breach
#

can you further elaborate? stick what?

tight grotto
#

the end of the button

#

i used the background-color thing

#

and it spans to the whole website

#

so what should i do
======fixed========

mortal socket
#

has someone hosted flask app on a custom domain using Apache ?

native tide
#

yes

#

and it made me want to cry.

mortal socket
#

can u show me the steps

native tide
#

that i cannot do, i got a ton of help myself and remember little owosad

mortal socket
#

kk

proud igloo
#

hey guys has anyone setup opentelemetry with django?

left jungle
#

has someone hosted flask app on a custom domain using Apache ?
@mortal socket Please, use Heroku.

late fjord
#

can you please guys tell me what the difference between authenticate and login

#

and what happens when we login a user without authenticating him

flint breach
#

@mortal socket Please, use Heroku.
@left jungle "how do to A" - "Use B" 😳

quick cargo
#

Heroku isnt even the same thing

#

like

#

Heroku is just a free host

#

not a actually deployment

flint breach
#

To sucesfully login, you have to authenticate the user

#

authenticating means prooving you are who you say you are

#

if you don't authenticate your users, anyone can claim they are someone, without prooving they are

quick cargo
flint breach
#

at that point, don't even use user profiles

#

if you're using django, authentication is built into the framework πŸ™‚

late fjord
#

got an idea, still don't get it, anyway, thanks

flint breach
#

basically, a login attempt is basically just a delivery of username&password from client to server

#

the server attempts to authenticate the user based on the credentials the client has sent

#

if the login attempt succedes (the username is found, the password is hashed and checked for equality with the one in the database, and if the check succeeds - maybe a bit more complicated but that's the jist of it) the client is authenticated. if it doesn't, the server sends back some kind of message that the authentication has failed, and that's where you need to input your credentials again, or recover a forgoten password or whatever

#

once you succesfully authenticate you usually get some sort of session/cookie being sent back to the client, where he sends said cookie in all upcoming requests to the server, implying to the server that they have sucesfully authenticated in the past

#

did that help?

#

feel free to ping me here if you don't quite get it

#

once it sinks in, it stays πŸ˜›

#

if you're interested in more, IAAA (identifcation, authentication, authorization, accountability)

wind walrus
#

If I want to deploy my Flask app to Heroku do I need to commit my .env file to Git?

#

It contains my secret_key as well as my email and password....

flint breach
#

sensitive data should not be commited to version control

wind walrus
#

Exactly, but how can I deploy to Heroku then?

#

I'm following a tutorial from this guy but he commited his .env file to Git...

flint breach
#

does heroku have a seperate section for enviorment variables

#

i imagine it does

wind walrus
#

Do I put my email/password here?

flint breach
#

basically you enter your env variables, secret keys and such, where only the vm or container where you run your app will have access to them

#

yea

wind walrus
#

Ahhh makes sense thank you!

#

And if I want to create an admin user

#

Do I have to change the code to create an admin user, commit that, then create an account, then change the code back to a normal user, then commit again?

flint breach
#

you're using django?

wind walrus
#

Flask

flint breach
#

aha, then im unsure, but you shouldn't need to hardcode any username/password

wind walrus
#

Okay!

#

Also one last question sorry - I'm using dotenv and its load_dotenv() with os.getenv() to load environment variables, but is that okay? Will Heroku be able to use the Config vars I inputted in the settings instead?

flint breach
#

yea, it should be fine

#

heroku on container setup will inject the enviorment variables into the container

#

where in your code, you will be able to retrieve them

wind walrus
#

Okay, thank you for your help

#

I hope it will work

flint breach
#

concerning the superuser question

#

in django you would something like this

#
heroku run python manage.py createsuperuser```
#

perhaps a flask equvilent shell command exists?

#

unfortunately not versed in flask so i can't tell you more

wind walrus
#

Okay, I will look into that, thank you

flint breach
#

goodluck!

proud igloo
#

hey guys I am getting a 500 behind wsgi for django

#

bt it isn't logging anything

#

to the console

#

if I had in debug it would throw a stack trace

#

how should I handle this?

flint breach
#

just when you setup wsgi, before it worked?

proud igloo
#

sorry

#

I don't mean the whole of my app is now throwing 500s

#

I just mean when it does

#

I want gunicorn to log it to console

#

/django

flint breach
#

so basically you're using gunicorn now, and it doesn't log into the console like the regular development server did?

proud igloo
#

yes

#

I have tried to implement sentry but that isn't working either strangely

flint breach
#

unfortunately haven't used gunicorn directly, so not sure

#

using nginx?

wild thunder
#

guys, how to make my ui responsive?

#

i'm using bs4

#

but it looks bad on mobile

rigid laurel
#

What does bs4 mean here?

wild thunder
#

bootstrap4

rigid laurel
#

Ah

#

I was thinking beautifulsoup and very confused

wild thunder
#

;P

#

how could i send this text to below the image and the form below the text

#

when the screen is small?

flint breach
#

look into the grid-column structure in bootstrap

#

col-lg-9 for example

azure saddle
#

is there anyone who is really good in JS and HTML??

true tendon
#

if you work with node for too long I think I start considering "no" for js

flint breach
#

Ask your question

azure saddle
#

me?

#

well I need to built a website login page that takes just the username and then puts that user into a random page

sour leaf
#

gud evening gentlemen,hope you r doing fine,I have a question that I did some research on but failed to find accurate resources,I'm creating a following system,and I was wondering whether I should cache the followers and followings for each user(if possible) or would it be just sent whenever the front-end needs it?

flint breach
#

Basically you wanna avoid the n+1 problem

sour leaf
#

@flint breach i'll read more about it,thank you!

acoustic oyster
#

Anyone here willing to lend me some quick help with React? Their discord is not as awesome as this one xD

native tide
#

lolol

green snow
#

im trying to run my slenium code on a VM,chromedriver gives the error:Getting Default Adapter failed. i tried gecko it faied:gecko unexpectedly exited
im on a vm hosted on aws

#

its a windows vm

acoustic oyster
#

do you have chrome installed? haha

#

and proper versions?

green snow
#

yes bro

#

i have th

#

latest ons

narrow zephyr
green snow
#

i have the proper versions @acoustic oyster

acoustic oyster
#

Sorry, I cant be much help, I just know that was a re-occurring error I had.

azure saddle
#

well @green snow maybe you have downloaded the wrong version of chromdriver or maybe the version of chrome you are using is so new that it is not supporting chromedriver

green snow
#

well i launched my instance yesterday

#

and downloaded chrome yesterday itself

#

i got the apprpriate driver

#

that suits chrome version but no luck

#

what about gecko?

azure saddle
#

ohk

#

yeh I'm searching BTW

green snow
#

ok ill wait

azure saddle
#

yes

#

Service geckodriver unexpectedly exited. Status code was: 69

#

like this?

green snow
#

exactly

azure saddle
#

ohk

#

Have you setup GeckoDriver properly? You need to provide the GeckoDriver location in System properties, as well as Firefox binary if you are using the latest versions.

Please check out this article for setup. The code snippets are in Java though.

http://www.automationtestinghub.com/selenium-3-0-launch-firefox-with-geckodriver/

#

stacks overflow is helpfull for that

green snow
#

i had simply downloaded gecko,and put it in desktop

azure saddle
#

give the exact path for it

green snow
#

the thing is all this worked perfectly on my home pc

azure saddle
#

like you give in chromedriver

green snow
#

i didnt have to give a pth or somehin

azure saddle
#

well try giving it

#

can you show your code?

green snow
#

i never gave any path on any of them in my home pc

#

ya ill share my code

#

gimme a sec

azure saddle
#

ohk np

lavish prismBOT
#

Hey @green snow!

Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:

β€’ If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)

β€’ If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:

https://paste.pythondiscord.com

green snow
#

i donno its not allowing txt file,this does?

azure saddle
#

well I think the problem is with just the driver and all yes?

green snow
#

ya

#

it worked perfectly on home pc

#

i jh

azure saddle
#
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import pyautogui


chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(chrome_options=chrome_options)

driver.implicitly_wait(45)

driver.get('https://accounts.google.com/AccountChooser/signinchooser?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&flowName=GlifWebSignIn&flowEntry=AccountChooser%27)
account=driver.find_element_by_xpath('//[@id="identifierId"]').send_keys('')
nextbutton=driver.find_element_by_xpath('//[@id="identifierNext"]/div/button/div[2]').click()
pswd=driver.find_element_by_xpath('//[@id="password"]/div[1]/div/div[1]/input').send_keys('')
nextbutton2=driver.find_element_by_xpath('//[@id="passwordNext"]/div/button/div[2]').click()
time.sleep(15)
meet=driver.find_element_by_xpath('//[@id=":jx"]/div/div[2]/span/a').click()
'''schedule meet'''
meetcode=driver.find_element_by_css_selector('body > div.Kj-JD.YY > div.Kj-JD-Jz > input').send_keys('')
joinbutton=driver.find_element_by_css_selector('body > div.Kj-JD.YY > div.Kj-JD-Jl > button').click()

allhandle=driver.window_handles
size=len(allhandle)
parent=driver.current_window_handle
for x in range(size):
    if allhandle[x] != parent:
        driver.switch_to.window(allhandle[x])


dismiss=driver.find_element_by_css_selector('#yDmH0d > div.llhEMd.iWO5td > div > div.g3VIld.vdySc.pMgRYb.Up8vH.J9Nfi.iWO5td > div.XfpsVe.J9fJmf > div > span > span')
dismiss.click()
time.sleep(2)
pyautogui.press('esc')
joindir=driver.find_element_by_xpath('//[@id="yDmH0d"]/c-wiz/div/div/div[4]/div[3]/div/div[2]/div/div/div[2]/div/div[2]/div/div[1]/div[1]/span/span')
joindir.click()



time.sleep(50)
driver.close()
green snow
#

on home pc:i installed choclatey then chromedriver,then ran da code,all good

#

and gecko i downloaded directly and ran alllgood

azure saddle
#

ohhkk

#

wait

green snow
#

yep

azure saddle
#

lemme see

#

selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH

#

@green snow

green snow
#

now

azure saddle
#

well

#

it gave the error that path is not defined

green snow
#

that part of the code was added to close a chrome notification

azure saddle
#

so I gave my own path

#

and it worked

#

obviously no password and email so it just opened the chromedriver and stoped

green snow
#

could hahe donv directly,driver=webdriver.chrome()

azure saddle
#

yeh

#

well

#

I did with chromedriver for you

#

so just give it the path

green snow
#

where exactly should i paste in the code which i sent to you

#

but there is one thing i forgot to mention

azure saddle
#

anywhere

green snow
#

excuse me for this

azure saddle
#

just put the exact path

#

waht?

#

what*

green snow
#

when i run the code it works till it signs into the google account

azure saddle
#

yeh

green snow
#

it stops when it searches the join meet button

azure saddle
#

mine too

green snow
#

nono u didnt get it

azure saddle
#

where is join meet button?

green snow
#

chromedriver actually works till there it doesnt gve any error till there]

azure saddle
#

well

green snow
#

meet=driver.find_element_by_xpath('//[@id=":jx"]/div/div[2]/span/a').click()

azure saddle
#

try using CSS_selector

#

for buttons

green snow
#

no

#

see

#

think of it like this

#

you know when you run the code onn the driver window it says devtools listeniing

#

which means allgood ,this works till signing in

#

and when after that it throws the error bluetooth port...

#

now if it was element error it wuld have shown like that

azure saddle
#

wait

#

I'm trying to login

#

I'm making a simple one

#

ok?

green snow
#

kk

azure saddle
#

not this complex

green snow
#

ya

azure saddle
#

just making it login

#

then you can do you work

green snow
#

let me remind you

#

this worked on my home pc

azure saddle
#

what?

#

ohk great

green snow
#

this driver problem was first encountered on aws vm

#

on home pc this line was sufficient

#

driver = webdriver.Chrome()

azure saddle
#

you want to login into Gmail

#

right?

green snow
#

no need for those 3 lines,whihc were added to block notifications

azure saddle
#

ohk

green snow
#

well till taht part driver works

#

this program is to automate my gogle meett

azure saddle
#

ohk

#

wait then

green snow
#

without even opening my hoome pc

#

ya sure

upbeat forge
#

what does this do? πŸ˜„

azure saddle
#

well @green snow it won't work for chromedriver

green snow
#

im ok with gecko

azure saddle
#

ohk

green snow
#

aslong as my automation work

azure saddle
#

well try this

#
from selenium import webdriver
import time

email = 'email'
password = 'password'

driver = webdriver.Chrome('C:\\Users\\DELL\\Desktop\\python codes\\chromedriver')

driver.get('https://accounts.google.com/ServiceLogin/identifier?flowName=GlifWebSignIn&flowEntry=AddSession')
driver.find_element_by_name("identifier").send_keys(email)
driver.find_element_by_xpath("/html/body/div[1]/div[1]/div[2]/div/div[2]/div/div/div[2]/div/div[2]/div/div[1]/div/div/button/div[2]").click()
#

I did this till here

#

I don't have that gecko

#

well this works

#

for logining

green snow
#

im a bit confused here

#

can u put this in my code

#

and also why it wont happen on chrome

azure saddle
#

not in chromedriver

#

and I'm not able to access chrome

#

yes sure

#

first just define the variables that you want to input

#

and then

#

just step by step find the xpaths or the names for the button that you want to click

green snow
#

i know tha

#

just the driver part f the code

azure saddle
#

ohk

#
from selenium import webdriver
import time

email = 'email'
password = 'password'

driver = webdriver.Chrome('your path to the browser')

driver.get('https://accounts.google.com/ServiceLogin/identifier?flowName=GlifWebSignIn&flowEntry=AddSession')
driver.find_element_by_name("identifier").send_keys(email)
driver.find_element_by_xpath("/html/body/div[1]/div[1]/div[2]/div/div[2]/div/div/div[2]/div/div[2]/div/div[1]/div/div/button/div[2]").click()
driver.find_element_by_xpath("/html/body/div[1]/div[1]/div[2]/div/div[2]/div/div/div[2]/div/div[1]/div/form/span/section/div/div/div[1]/div[1]/div/div/div/div/div[1]/div/div[1]/input").send_keys(password)
driver.find_element_by_xpath("/html/body/div[1]/div[1]/div[2]/div/div[2]/div/div/div[2]/div/div[2]/div/div[1]/div/div/button/div[2]").click()
#

this will log you in

green snow
#

okay

#

ill try giving path this time

azure saddle
#

yes

green snow
#

didnt wrk

#

same error

#

the driver works to a point and then throws erroe

azure saddle
#

well it won't work in the driver cause gmail doesn't allow to login with any automated browser

#

If you are able to access the chrom by any way then it great

green snow
#

it worked till signing in

azure saddle
#

yeh IK bro

green snow
#

in home pc it ran full

azure saddle
#

I'msaying na

green snow
#

joins the meet and leaves

azure saddle
#

with what?

#

chromdriver?

green snow
#

ya

azure saddle
#

it can't lmao

green snow
#

the whole thing wrked

#

it did

azure saddle
#

gmail wouldn't allow

#

lol

#

then it's great

green snow
#

it worked bro

azure saddle
#

ok ok

green snow
#

well

azure saddle
#

then run in the home PC maybe

#

suggest

green snow
#

no i want to fully quit electronics for a week

#

severe neck pain

azure saddle
#

oh lol

#

ohhkk

#

well then

green snow
#

google may not allow one notification

#

wat u r talking about not being possible

azure saddle
#

I told you what I knew so from here I can't help

#

sorry

green snow
#

so at tha tpart i use pyauogui and press esc button to close that one alert box

azure saddle
#

wat u r talking about not being possible
@green snow gmail says that it will not log you in cause the browser is not safe

#

so at tha tpart i use pyauogui and press esc button to close that one alert box
@green snow yeh I got it

green snow
#

anyways thx for your time

azure saddle
#

no problemo

green snow
#

i have asked for help in many servers utube

azure saddle
#

ohhkk

green snow
#

ill tell you once i get it sorted out cya

azure saddle
#

yes I'll wait

#

bye

azure saddle
#

anybody good at front end?

acoustic oyster
#

No, what do you need help with?

wild thunder
#

guys

#

good night

#

i'm having problem with pipfile and pipfile.lock

#

it's not locking

#

the website was running fine, i added a function and tried to deploy it

#

it was working fine locally

lavish prismBOT
#

Hey @wild thunder!

Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:

β€’ If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)

β€’ If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:

https://paste.pythondiscord.com

wild thunder
late fjord
#

!code-blocks

lavish prismBOT
#

Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.

To do this, use the following method:

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

Note:
β€’ These are backticks, not quotes. Backticks can usually be found on the tilde key.
β€’ You can also use py as the language instead of python
β€’ The language must be on the first line next to the backticks with no space between them

This will result in the following:

print('Hello world!')
late fjord
#

@flint breach What I am going to ask is kinda a personal question, but what I wanna know is if you have had any experience with freelancing and do you recommend it. (the personal question: what is the average price of a website you make?)

#

what do you mean by that

#

@native tide you are a beginner and you want to find where to learn

#

@native tide I advise you to go to youtube and search for dennis ivy django tutorial or Corey Schafer's one

native tide
#

!resources @native tide

lavish prismBOT
#
Resources

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

azure saddle
#

No, what do you need help with?
@acoustic oyster making a webpage lol

flint breach
#

how do you guys handle usage statistics for users (in django)

#

for example you offer several services, for example downloading a file in several formats

#

and you would like to keep track of how much each user downloads

#

how would you handle something like that in a generic way

#

you could for example keep track how many times he sends a post request to that url, but what if the endpoint url chnages for example?

#

like what, if you have 40 different services like that

#

how do you tackle something like that

lavish prismBOT
#

Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.

To do this, use the following method:

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

Note:
β€’ These are backticks, not quotes. Backticks can usually be found on the tilde key.
β€’ You can also use py as the language instead of python
β€’ The language must be on the first line next to the backticks with no space between them

This will result in the following:

print('Hello world!')
native tide
#

Hi,
what are some good resources with which i can build costumed html templates instead of writing them manually?

#

bootstrap

#

themes

#

do you mean themeforest?

#

What service do you guys use for storing images? I was using file system storage but heroku doesn't like that and makes them disappear after a while.

#

doesnt aws have something for that?

#

Should I give aws s3 a shot or, is there sth better?

#

this is quite annoying cause' now I might not be able to compress them and need to change the whole system

#

Or I might switch from heroku 😐

#

what do you mean by "automate all the tasks"

#

I ve done that

terse viper
#

DO doesn't have a cheap bucket storage, so AWS S3 is by far the cheaper option if you're just storing images

native tide
#

Nah..it's not a small project

terse viper
#

for S3 youl'l be charged for usage, so typical $0.023 per gb

#

plus transfer

native tide
#

that's not bad at all.

terse viper
#

yeah, it really isn't, but you do need to factor in transfer costs if you're moving data around a lot

#

but for a few files, it's not bad at all

#

(plus you'll likely be in the free tier and not pay anything)

native tide
#

What if a lot of people enter the website and all request the data from the aws service?

#

would that charge the client more?

terse viper
#

yes

native tide
#

😦

#

that's bad..if it's with respect to my web traffic

terse viper
#

you pay for three things:

  • storage ($0.023 per gb)
  • operations ($0.0000004 per GET or other requests) usually one or two of these per request
  • transfer ($0.09 per GB but first GB is free)
native tide
#

$0.0000004 per GET or other requests

#

ugh

#

that's good :)))

#

cause' I do more gets than posts

flint breach
#

aws s3 is preety cheap yea

terse viper
#

if you get a million requests for a 100kb file, you'd pay this:

  • storage (not even going to calculate this, it's so tiny)
  • operations: 40 cents
  • transfer: $9
native tide
#

btw.. the aws bucket, is that like a folder in my filesystem? Can I create a bucket for each folder where I have pictures inside?

#

I have a folder with pictures for the project page.. then another folder with pictures for construction page

terse viper
#

aws buckets live in AWS, while there is a way to mount that like a filesystem, normally you don't

#

yes, it's somewhat like a folder with stuff in it, and when you browse it on the online browser, it looks pretty much like a filesystem. and the path is separate by slashes, so once you set up HTTP access to your bucket, you can work out the full address easily

#

BUT

#

it only looks like it has folders, it's actually an illusion, and there's no inherant folder structure

#

you can treat it as having folders, but in reality it doesn't, a fact that occasionally comes up in the way some of the functions work for fetching lists of files

native tide
#

is it slower than the file system?

terse viper
#

that's a hard question to answer

native tide
#

because in the filesystem you put them once and then you point to the images

#

I guess.

terse viper
#

well, you can't really compare it, too many factors

#

ok, you can, but this'll take some explaining

native tide
#

by and large..

terse viper
#

firstly: speed is one or both of two things: latency and bandwidth

#

latency being how long it takes before you receive the first bit of data after your quest. and bandwidth being how much data you can receive per second

#

S3 is generally higher latency, but also medium bandwidth compared to disk running in AWS's datacentre, but here's where it gets more complex: there are multiple tiers of disk in AWS as well

#

not only do you have the option of selecting an SSD or a magnetic drive; but also AWS allocates IOPS based on not only the size of these disks that you allocate, but also a credit/allowance system that lets them get higher IOPS for small bursts

native tide
#

so in a nutshell, if I pay I ll get higher bandwidth

terse viper
#

furthermore, you can choose where the disk is, the default disks aren't actually plugged directly into the same mobo that your VM is on, it's elsewhere on the rack, or even elsewhere in the datacenter, linked by high-bandwidth network; this increases disk latency. You can choose to pay more for a "local" drive that is physically plugged into the same hardware your VM is running on, and this'll get you the best latency

#

so yes, you can chose:

  • local disk vs somewhere else in the rack/datacenter
  • disk of various sizes impacting the IOPS allowance
  • you can pay to reserve IOPS in addition to the above
  • you can pick between magnetic and SSD

the speed and latency of S3 fits ... somewhere... in here

#

it's definitely higher bandwidth than most magnetic disks; it's probably higher bandwidth than some SSD configurations. It's higher latency than a local disk, it's probably higher latency than default disks as well. But its latency and bandwidth is also potentially throttled by your VM's network allowance, since you're on shared hardware, and if you use more network capacity, AWS may throttle you back to allow other tenants access. This throttling is also usually based on VM size - larger VMs get more network capacity

#

I hope you can see what I meant by "can't really compare it, too many factors"

native tide
#

yeah..

#

basically what happens

#

in my case

terse viper
#

and here's another thing, which is more relevant for your use case, is that the S3 bucket can be set up for a direct HTTP access, so you don't need a server just to serve files

native tide
#

heroku doesn't update my github static files whenever I dynamically post images from the website and save them in the file system.

terse viper
#

if you needed ultra-high-speed (low latency) access to your files, you'd stick a CDN in front of your S3 bucket. This will cost more, but it'll make your data accessible much faster

#

curveball: Google also provide bucket storage

#

prices are similar, but Google's Firebase service has quite a large free tier as well

#

their free tier is 5GB, transfer 1GB/day, 50k/day ops

native tide
#

pretty cool, I ll look into it

terse viper
#

if you do, also consider Firebase hosting as well, it's also quite a good web host and great for static websites (including those built with webpack)

#

I basically run 90% of my sites though firebase, using the free tier hosting, plus Firebase Functions (equivalent of AWS Lambda) to run any light APIs (often written in Python - like Lambda, they also use Flask as the runtime)

#

plus serverless databases. It's basically ideal for a JAM stack

native tide
#

do you use flask or django?

terse viper
#

flask

#

I'm not sure you'd be able to fit django onto serverless, you'd probably need to run a server

#

(the AWS equivalent of Firebase involves AWS Amplify, AWS Cognito, AWS Lambda, and S3, by the way, features are more or less similar, different pricing structure)

native tide
#

I used another service from aws (ses), that's why I keep mentioning it

#

it was pretty easy to set up

terse viper
#

ah ok, interestingly Google doesn't have an equivalent of SES, they make you use Sendgrid

#

but.... if you sign up to Sendgrid through Google's cloud web console, you get 4x the free tier allowance versus signing up to Sendgrid from their own website

native tide
#

I see you've exploited everything about these services :))

#

that's good

terse viper
#

yep, I switched over from AWS to Google a few years ago. They're both good, I'm more familiar with google today, but I don't see any as particularly good or bad, they both have their benefits. I think Google's free tiers are better at the moment, but are slightly more expensive currently (they jostle for price very often)

native tide
#

silly question: you using a loading screen while waiting for requested data?

terse viper
#

usually. I build most of my frontends in vue, and I use the vuetify component library, which has by default a :loading property defined for many components, so it's super-easy providing loading bars or spinners on buttons

native tide
#

I see..for this project I used html and sass

terse viper
#

so mostly an axios().then().finally() with the loading state unset in finally

native tide
#

:)) that's pretty nice, I mean I think aws s3 has callbacks on its get_reponse method as well.

terse viper
#

or try/except/finally for awaits

#

I'm not a good designer, so I use a component library do all the work for me

#

vue+vuetify is what I normally use. so all my sites look super-bland, but they don't look bad

#

vuetify is mostly similar to other material component frameworks, it works well with vue, but doesn't look that much different to material-ui for react for example

#

but since it defines a bunch of components for you - cards, buttons, inputs, and all the usual flexbox things you'd expect, if you stick to these components, then your site will look like pretty much any other Material UI design site. Which doesn't stand out, but frankly is better than anything I can do

late fjord
#

If I know djagno should I learn flask

#

@native tide

#

@terse viper

terse viper
#

yes

#

flask is nice and lightweight, good for lots of things that don't need or don't fit into a django backend

#

and honestly there's not a lot to learn to be able to do useful things

true tendon
#

imo the decision point is whether you're using a database

#

yes, just use django. no, flask is probably better

terse viper
#

somewhat complex decision here, I don't think it's necessarily a "use django if you're using a database"

#

for me, the decision is usually: do I need a webserver that provides API, ORM, and MVC? if yes to all three, use Django

#

there's a lot of instances where the answer is no. For example, my current preferred stack is Vue (which does MVVM, and doesn't need Django's MVC); graphql (which doesn't make use of Django's API/CRUD stuff), and in fact integrates very well with sqlalchemy (which in my opinion is a better ORM than Django's)

#

so this particular stack for me doesn't require Django at all, and in fact works quite well with flask instead. the specific stack looks like:

  • vue.js (or really any other javascript frontend framework)
  • flask
  • graphene/graphql
  • sqlalchemy
#

and that's why I recommend learning flask if you're asking about whether you should learn something - it's useful for a lot of things. Django isn't the only way to do backend

native tide
#
able object.```
#

can someone help me out?

terse viper
#

looks like you defined user table twice

#

did you make a copy/paste error and forgot to rename the table you pasted?

fair agate
#

What would the best way to incorporate an existing Website into a Django application? I want to basically build a modular frame for a site and implement other functions outside the site - how can I accomplish this?

glass sandal
#

@fair agate Just move all the html files to templates folder like :

mv website/*.html djangoWebsite/temps/

And do the same with static files , then you have to rewrite the links and hrefs in the templates .

#

That's how I do it*

fair agate
#

what about actually loading up a webpage in full?

#

say there is an external site I want to build a frame around as a temporary measure until we can rebuild the site in Django

glass sandal
#

Then irdk

native tide
#

Hi

#

I couldn't find any specific channel for web scraping, can I use this one?

flint breach
#

Sure

wind walrus
#

In my Flask app, I create a folder in static for each user to store their static files for their posts like images

#

Static/users/{username}

#

I do this with os.mkdir()

quick cargo
#

i really wouldnt do that

wind walrus
#

Will this work if I deploy it to Heroku and host my static assets on amazon S3?

#

Oh rly? What’s the alternative?

#

Do I store them by file type?

quick cargo
#

You should remember Flask wont be the thing (Or shouldnt be the thing should i say) serving static files

wind walrus
#

Like static/images and static/videos or sth?

#

Yeah exactly, looking into S3

quick cargo
#

Any static data is normally handled by the Outer server like Nginx or apache

wind walrus
#

So how should I be organising files?

quick cargo
#

an easy method would be have a single static folder, or a folder with categories and generating unique ids

wind walrus
#

If I have a single static folder and al user uploads go to that folder, wouldn’t it become cluttered? Or is that just the way it is

quick cargo
#

or a corosponding ID related to the post number or something

wind walrus
#

Ah ok

#

I could just hash the image name (e.g user uploads β€œimage.jpg”) to guarantee the name will be unique?

quick cargo
#

if the names are the same and the process is the same the hash will be the same

#

idk how you have your thing laid out overall but

static/images/post_1_thumb.png or something

#

like you can always rename the file

#

that way when you load the posts you dont need some special system to load the images

#

just get the post number and serve the corresponding image to go with it

wind walrus
#

What if I want the posts to accept all file types? Like an embedded spreadsheet or a video or sth

quick cargo
#

i mean you dont have to change the extension

#

you can just change the name and keep the extension

#

tho you should have some extension filtering

wind walrus
#

So in general it’s not okay to dynamically create folders inside static?

quick cargo
#

otherwise people can easily inject all sorts into your system

#

Its generally a bad idea imo

wind walrus
#

So do I like

#

If the file extension is jpg png etc then store in static/images

#

If it’s .csv store in static/spreadsheets

#

If it’s in .mov .mp4 etc store in static/videos

quick cargo
#

you can do something like that yeah

#

I tend to have a static file area for static stuff for the site then another static folder for user data stuff

wind walrus
#

Ah okay that makes so much more sense thank you!

#

Ah, makes sense

#

So like

#

Static/users/images

quick cargo
#

i tend to have a seperate area entiely

#

Like my site stuff goes in xyz.com/static
while stuff which is changed or what ever is xyz.com/content or something like that

lavish canopy
#

Question for anyone out here, has anyone successfully written HTML emails out of Django Admin?

#

I'm working on a site right now that needs to use this feature for something like Newsletters, but I wasn't quite sure how I would implement it in Django. I also was hoping to use something like Vue + CKEditor or something in order to facilitate this

pulsar ivy
#

Hey guys, i have one question, is it possibke to create custom overlay in ohotoshoo and apply it over sliders???

elfin peak
#

no clue

#
import flask

app = Flask(__name__)

@app.route("/")
def home():
    return "Hello, welcome to the Lumber Legend's main page!"


if __name__ == "__main__":
    app.run()

I'm using Pycharm and this is returning an error:
(venv) D:\codyk\Coding.Aprojects\Website>python "website.py"
Traceback (most recent call last):
File "website.py", line 3, in <module>
app = Flask(name)
NameError: name 'Flask' is not defined

odd swallow
#

i have a project design question. i have a flask backend and react frontend. my python file requires an image to use OCR api and parse the image for text on the backend.

So if i upload a file locally, it'd make sense to put it in static/img, but where would i put that image on a hosted website?

Is it possible to store that image where the flask is deployed (say heroku?) or should i explore options to store that image data into mongodb (GridFS)

native tide
#

what image doesn't work?

#

register.jpg?

#

try {{ url_for('static', filename='pic/register.jpg') }}

ripe goblet
#

idk flask. sorry. i only know django 😦

native tide
#

Question about AWS S3 and html file inputs: Say I have a form where I take image files from users and then I want to post them to my AWS S3 bucket. I don't want to pass them directly using pre-signed URLs because I'm compressing/modifying the images. Is it okay if I first save them to my filesystem and then use the s3_client.upload_file and get the images from the filesystem? The thing is, I host my website on Heroku which works with ephemeral filesystems and at some point the images will disappear from my folders. However, I was thinking this is an advantage for me since I need the image in my filesystem only as soon as I finish uploading them to my S3 bucket. Is this a good approach, any hints pls?

modern hearth
#

Hey guys. So I am using the factory approach for my flask app.

#

There is one problem though.

#
# database.py
engine = create_engine(f'sqlite:///test.db', convert_unicode=True)
db_session = scoped_session(sessionmaker(autocommit=False,
                                         autoflush=False,
                                         bind=engine))```
#

in their tutorial, they create a database session on the import time.

#

The problem here is that app.config['DATABASE'] should be probably used instead of the hardcoded value and I cannot access the app instance at the import time.

#

How should I go around this? Should I create the db_session inside the create_app function in _init_.py?

#

Please tag me in case you know a solution.

stone wren
#

#Flask

this is the response I got when I filtered UserModel by id(10003) --- UserModel.query.filter_by(id=10003)

how do I list users and all info except packages that has state 'delivered' and 'deleted'

user > packages > all except (not deleted and not delivered)

[
   {
      "id": 10003,
      "packages": [
         {
            "id": 218,
            "states": [
               {
                  "created_date": "2020-07-08T07:07:25.661169",
                  "state": "Declarations"
               },
               {
                  "created_date": "2020-07-11T08:01:52.928634",
                  "state": "Deleted"
               }
            ]
         },
         {
            
            "states": [
               {
                  "created_date": "2020-06-29T13:52:45.423667",
                  "state": "Delivered"
               },
               {
                  "created_date": "2020-07-07T14:03:11.147933",
                  "state": "InternalStorage"
               },
               {
                  "created_date": "2020-07-08T06:06:08.517589",
                  "state": "Delivered"
               }
            ],
            "product_category": "BagsAndLuggages"
         }
      ]
   }
]
lament current
#

I am working on djnago forms, so what I want is, I have a form choice field city when user selecet it, and there is onther field named radius automatically filled. How cann I accomplish this?

modest scaffold
#

how do i load a stylesheet from a child template onto the parent template

#

ive tried this: in the parent template <head> <meta charset="UTF-8"> <title>{% block title %}{% endblock %}</title> {% load static %} <link rel="stylesheet" href="{% static 'base.css' %}"/> {% block additionalStyles %}{% endblock %} </head> and in the child template {% extends 'base.html' %} {% load static %} {% block additionalStyles %}<link rel="sytlesheet" href="{% static 'rants.css' %}"/> {% endblock %}

#

this doesn't seem to work and im not getting any error can someone please help me out

late fjord
#

@modest scaffold you need to put both files in file called templates

#

@modest scaffold and in that file you should create another file that has the same name of you app ''templates/appname/file.html and that file should be inside that app 'the templates file should be inside the app that you created with python manage.py startapp 'appname'if you are in windows and python3 manage.py ...'
And inside you child template you should write this line in the top{% extends 'appname/file.html' %}

#

@modest scaffold like that the child template will extend from the parent template, hope that makes sense, feel free to ask more questions, I'll do my best to answer them

flint breach
#

ye, you're missing an extend, otherwise it doesn't know which template is the parent template