#web-development

2 messages ยท Page 112 of 1

placid vale
#

i have used sublime and vscode

late gale
#

i used it once when i was learning html since 4 years lol

placid vale
#

but vscode is gr8

#

specially it plugins

late gale
#

Vscode is awesome for web developement

placid vale
#

yeah

#

specially its live server plugin

late gale
#

Pycharm is awesome for other things like Machine learning

#

agreed

placid vale
#

i will later also try pycharm

mental prawn
#

guys if i want to make a website and me mysel want tof code it how should i do it?

placid vale
#

when i will learn something else ๐Ÿ˜›

#

:/ wdym?

#

just write css html and js

late gale
#

@mental prawn you wanna code a website ?

mental prawn
#

no no no

tardy heron
#

who cares. Try out what you like. If you want, get vim and learn it and install a plugin installation plugin and write a 200 line config to make it work like you want. It would work too.

mental prawn
#

i want to make a website, and i dont want to use wix or webflow or something, i want me mself to code and bring the code to life how am i suppose to do it?

placid vale
#

just code

late gale
#

you need to learn frontend and backend

tardy heron
#

not by changing your editor.

late gale
#

frontend = html , css , js or sass

placid vale
#

yeah learn

late gale
#

backend = django or flask

#

if u are talking about python

#

if u want to build using php so laravel

placid vale
#

never heared django

late gale
#

if u want to build using C# so .Net

mental prawn
#

i want to build using python

late gale
#

@placid vale you never heard anything

#

@mental prawn So either choose django or flask

#

and i highly recommend Django

placid vale
#

i am now days learning css

mental prawn
#

well i heard that django is a bit hard comparing with flask

late gale
#

it all depends on your presepctive

#

I find Django is much better and easier

placid vale
#

i am a beginner

late gale
#

@placid vale Welcome ^^

placid vale
#

everything is easy just practice!

mental prawn
#

same im a beginner on python i know a bit of if's and while's and other variables

#

so i want to test my knowledge on making a website

late gale
#

well you have a long way to go still

#

you need to learn oop , datastructures and algorthims

#

then u go for django as a backend

#

but u still have to learn html and css and javascript

mental prawn
#

datasturcture like panda or?

placid vale
#

you need to learn oop , datastructures and algorthims
@late gale what are those i have heared about them are they necessary?

mental prawn
#

i think you still can make a website using python

late gale
#

pandas is a library

#

Data structures and algorthims are the way to how to solve problems

mental prawn
#

yes and there are many more library's

placid vale
#

oh

mental prawn
#

like pd.Datastructure

late gale
#

noo it's a technique for problem solving

placid vale
#

for bot we need ? python?

#

only?

late gale
#

discord bots ?

placid vale
#

yeah

late gale
#

you dont need python to create a discord bot

mental prawn
#

soo do i need to learn html n js to make a website or?!

late gale
#

any language can build a discord bot

placid vale
#

๐Ÿ˜ฎ

#

i have heard discord.js?

late gale
#

@mental prawn html and css js are necessary yes because they are anything you see at website "FrontEnd"

#

buttons , texts images

#

all of them are frontend

#

designs colors

#

anything u see is a frotnend

#

unlike backend

#

@placid vale discord.js is nice

placid vale
#

and they are super easy!!

late gale
#

Agreed

#

html css are easy

placid vale
#

yeah

#

js little tricky

late gale
#

agreed

#

and it might be too hard if u get to advanced javascript

#

as it says 1 + "1" = 2 and "1" + 1 = 11

#

something like that cant remember

placid vale
#

dont scare me๐Ÿ˜ซ

tardy heron
#

heh

late gale
#

xDD

mental prawn
#

๐Ÿ˜ฆ

late gale
#

you dont need advanced javascript

#

just vanilla is fine

#

with html and css

#

beside ur backend framework

placid vale
#

hmm

late gale
#

you can build a website without a backend but you can't build a website without a frontend

placid vale
#

agreed

#

backend for forms etc

#

for forms use google forms

mental prawn
#

i never heard about front and backend's ๐Ÿ™‚

late gale
#

you have a long road to go ^^

placid vale
#

hmm

late gale
#

but its nothing hard

tardy heron
#

it is hard

placid vale
#

agreed

tardy heron
#

๐Ÿ˜„

late gale
#

nope it's not

mental prawn
#

soo ugh

late gale
#

If u understand something hard that means its not

#

so all you gotta do is understand

tardy heron
#

i'm doing an api and learning typescript and angular. Never did js or web things before. It's hard enough ๐Ÿ˜„ Learning html, css, sass, js, typescript, flask, jwts, etc

#

theres so much stuff

placid vale
#

html soo much easy

#

just remember tags

tardy heron
#

still it's something ๐Ÿ™‚

mental prawn
#

any ideas how i can improve my python skills?

placid vale
#

practice?

mental prawn
#

wdym?

placid vale
#

idk about python ๐Ÿ˜›

late gale
#

@mental prawn keep making projects everytime u learn something new

mental prawn
#

like ?

late gale
#

u said that u learned the while loop and if statements

mental prawn
#

yes

late gale
#

try to create a software for someone's interview

#

so they can write their name their age and answer questions

placid vale
#

@late gale nice to meet you
now i need to go for school homework ๐Ÿ˜›

late gale
#

and different ages means different questions

mental prawn
#

good idea ๐Ÿ™‚

late gale
#

@placid vale same here ^^

#

you have to use your best friend " Google " for basic projects

mental prawn
#

wow @late gale you know so much about programming!

late gale
#

that way will improve your knowledge

placid vale
#

@placid vale same here ^^
@late gale u also school homework ๐Ÿค” ๐Ÿ˜›

late gale
#

and will also tell you a lot of ideas to do

#

Thank you ^^

mental prawn
#

well i tried making like a small project where its like an online restaurent

late gale
#

@placid vale I am 18 but i dont have a homework ๐Ÿ˜›

#

@mental prawn always go with something basic

mental prawn
#

i tried n tried but failed ๐Ÿ˜ฆ

late gale
#

go with basic things

#

and keep going for different levels

mental prawn
#

or making a small game

#

like xo

late gale
#

u can build the snake game

#

or xo

#

good job

mental prawn
#

the issue is that when i try making some project i get confused and then get stuck and then i stop

late gale
#

and i recommend not to start with games start with something u have studied

#

so u dont lose confidence and hope

#

and along the way

#

keep going for ur next level

#

and i believe that u will create your dream website ^^

mental prawn
#

Thank you ๐Ÿ™‚ i appreciate it

red perch
#

So as i asked yesterday i had a problem with Flask, ```py
from flask import Flask, redirect, url_for, render_template

app = Flask(name, template_folder='templates')

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

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

mental prawn
#

im not sure ๐Ÿ™‚

red perch
#

idk if these links are correct but i guess it will not be the fault for infinet loading with no errors

#
<link rel="stylesheet" href="{{ url_for('assets', filename='main.css') }}" />
    <link rel="stylesheet" href="{{ url_for('assets', filename='responsive.css') }}" />```
patent thistle
#

Hey anyone know abt what the heck is WebRTC . I heard about the webSocket and use it to build the chat app that allow birectional connection. Is WebRTC same as WebSocket or is diffrent then what is the diffrence?

stable kite
#

@patent thistle WebRTC means Web Realtime Comunication

#

@patent thistle The main difference is WebRTC uses Peer to Peer connection while Websocket uses client server connection

cold haven
#

Morning

native tide
#

Hey, I want to create some kind of a counter to a model, basically every time a user clicks a button, 1 num will be added to the counter, basically like counter += 1.

How do I do that? (Django)

quick cargo
#

I'd do that with js tbh

#

Aka ajax

native tide
#

um let's say then whenever a user is being added to a group

#

Is it still possible to do that with js?

quick cargo
#

You'd just use it to interact with the backend without reloading the page

snow sierra
#

which is better and useful HTML forms or ModelForms ??

placid vale
#

@snow sierra arent bot same

#

if u dont want to code and do backend u can try google forms

snow sierra
#

thank you for understand ๐Ÿ™‚

#

and what you think which is better?

placid vale
#

ahh never tried modelforms

halcyon lion
#

Can you guys point me in the right direction. I want to display few items on the home page: most viewed and most recent. how do i do that?

cold haven
#

I would check if there's a lib for that first.

#

Not sure, but can be implemented in an ORM probably

#

You can store the most frequent and recently used transactions in a separate table

#

Maybe do many to many relationships

#

@halcyon lion

halcyon lion
#

i think i've done it in the past but i am a beginner with django ๐Ÿ˜„

#

and if i can remember correctly i had a like counter ๐Ÿ˜„

#

and u can just click as much as u want

cold haven
#

Yeah that works as to the most frequent

#

Sort by likes

#

What about recently used? You may need a timestamp

halcyon lion
#

oh man ๐Ÿ˜„

#

this is hard to learn ๐Ÿ˜„

#

i have never studied html, css and js

#

and now i have to learn all of those + django for 2 months while working 8h a day :d

patent thistle
#

Hey anyone know abt what the heck is WebRTC . I heard about the webSocket and use it to build the chat app that allow birectional connection. Is WebRTC same as WebSocket or is diffrent then what is the diffrence?
@patent thistle .

#

can any one tell me more descriptive i dont understand the bot answer

worn basin
#

Anyone have experience with setting up django-sass-processor? Im dealing with old scss files being loaded and reseting the browser cache doesnt solve my issue so I'm presuming I missed something when it comes to setup

late gale
#

can somoeone please help me authenticated users can see other profiles but unauthenticated can't .
here is my views.py

class UserProfile(DetailView):
    model = User
    template_name = "users/profile.html"
    context_object_name = 'user'

and the template

                {% if user.is_authenticated %}
                <li class="nav-item cta"><a href="{% url 'Profile' request.user.id%}" class="nav-link"><span>{{ request.user.username }}</span></a></li>
                {% else %}
                <li class="nav-item cta"><a href="{% url 'Contact' %}" class="nav-link"><span>Contact</span></a></li>
                {% endif %}
late gale
#

fixed it

devout coral
#

Good, I was just about to help

late gale
#

i should add

                {% if request.user.is_authenticated %}
                <li class="nav-item cta"><a href="{% url 'Profile' request.user.id%}" class="nav-link"><span>{{ request.user.username }}</span></a></li>

instead

#

i have another problem

#

haha

#

on the update profile

#

let me show it to you

devout coral
#

Ok

late gale
#

there

#

here is my views.py

class UpdateProfile(LoginRequiredMixin, UpdateView):
    model = Profile
    template_name = "users/update_profile.html"
    fields = ['user']

    def form_valid(self, form):
        form.instance.author = self.request.user
        return super().form_valid(form)

and here is the template

devout coral
#

And you are getting this error when the user does not exist? Or is not authenticated?

late gale
#

i am getting this error whenever an authenticated user clicks on the edit button so it directs him to the update page so he can update his profile

#

and here is the urls.py

    path('<int:pk>/profile/update',user_views.UpdateProfile.as_view(), name='Update_Profile'),
devout coral
#

Ok, well I can tel you that error means that the field you are paso to the crispy forms filter is none. So do a print or something to ensure you have a form being passed.

late gale
#

nah it's working i've opened the shell and got that profile and whenever i say profile.user.username it shows that person's username

devout coral
#

Did you spell all the fields right?

late gale
#

i commented all the fields except the user so i can see if its doing ok

#
class Profile(models.Model):
    user = models.OneToOneField(User, on_delete= models.CASCADE)

    bio = models.TextField(max_length=300)

    Committees = (
        ('IT','IT'),
        ('Design','Design'),
        ('ER','ER'),
        ('Design','Design'),
        ('Marketing','Marketing'),
        ('Coaching','Coaching'),
        ('Media','Media'),
        ('Branding','Branding'),
    )
    committee = models.CharField(choices=Committees, max_length=10, default='')

    position_list = (
        ('Member', 'Member'),
        ('Head', 'Head'),
        ('Vice', 'Vice'),
        ('President', 'President'),
    )
    position = models.CharField(choices=position_list, max_length=10, default='Member')

    awards = models.TextField(max_length=300, null= True)

    experience = models.TextField(max_length=300, null=True)

    achievement = models.TextField(max_length=300, null=True)
    
    image = models.ImageField(default='default.jpg', upload_to='profile_pics')

    def __str__(self):
        return f'{self.user.username} Profile'
#

let me try to add all the fields and see if thats working

#

not working

devout coral
#

Ok since it looks like you have multiple things going on in that template can you comment out all the fields but one and then check. So we can narrow the issue down to one field.

#

Then we can start adding them back one at a time

late gale
#

sure

cerulean forge
#

guys i have an issue while using kivvy

late gale
#

ok now i commented all the fields except that

<form method="POST" enctype="multipart/form-data">
              {% csrf_token %}
              <div class="form-group col-md-4 mb-0" >
                {{ profile.user.image|as_crispy_field }}
              </div> 
devout coral
#

And you get the error?

late gale
#

yes

devout coral
#

Ok cool. Wait, thatโ€™s not a form field. Thatโ€™s a model field

late gale
#

oh ok wait

#

let me comment it

#

cool so i commented the everything and the error is gone without any model field has been showing

#

now i uncommented form but commenetd the model field

#

and it works

#

so the problem should be in the model fields

devout coral
#

No

#

The problem is that a mode field cannot be used in a form

#

So itโ€™s not the field itself

#

You need to make a form for it like a modelForm

late gale
#

so the model fields are causing this error

#

but why

devout coral
#

Yes, because they are not formFields. Crispy forms expects a form field. All you are doing is fetching the attribute by doing profile.user.image.

late gale
devout coral
#

Ok, so just import the form in the view. Then instantiate it inside the class and pass it to the template

late gale
#

ok let me try

#
class ProfileUpdateForm(forms.ModelForm):
    Committees = (
        ('IT','IT'),
        ('Design','Design'),
        ('ER','ER'),
        ('Design','Design'),
        ('Marketing','Marketing'),
        ('Coaching','Coaching'),
        ('Media','Media'),
        ('Branding','Branding'),
    )
    committee = forms.ChoiceField(choices=Committees, required=False)    


    class Meta:
        model = Profile
        fields = ['bio', 'image', 'position' ,'committee', 'achievement','awards', 'experience']

here is the forms.py
i believe the fields are added right ?

#

or shall i add it in the class itself

devout coral
#

Yes, is are you passing that form as profile?

late gale
#

yes thats it

#

i also want to display the email from the user from that class

class UserUpdateForm(forms.ModelForm):
    email = forms.EmailField()
    class Meta:
        model = User
        fields = ['username', 'email']

and his username

#

lets just focus on the profile thing

devout coral
#

Ok could you just comment out everything in the form and replace it with {{ profile }} assuming the profile variable is the form itself

late gale
#

sure

devout coral
#

I just want to make sure you are actually passing that to the template

late gale
#

It's not showing the form fields but it shows the <username of the person> Profile

#

as a text

devout coral
#

Yep, I donโ€™t think you are passing the form itself.

late gale
#

so you mean that profile isn't the form ?

#

its not showing the forms yes

#

it only shows the value

devout coral
#

Correct. Do {{ profile.get_cname }}

#

In template

late gale
#

nothing appears

#

I found that when i removed |as_crispy_fields it doesnt show the error

#

but still there are no forms

devout coral
#

Alright, I was trying to just ensure it was indeed the wrong object type by printing the class name

#

Yeah, I think you are not passing it the form. Post the view again please

late gale
#

ok

devout coral
#

The view please

#

Where you have class blah blah

late gale
#

ooh srry

devout coral
#

No worries

late gale
#
class UpdateProfile(LoginRequiredMixin, UpdateView):
    model = Profile
    template_name = "users/update_profile.html"
    fields = ['user','bio','committee','position','awards','experience','image']

    def form_valid(self, form):
        form.instance.author = self.request.user
        return super().form_valid(form)
#

there

devout coral
#

Ok, I do not think you are able to pass more than one form to UpdateView

late gale
#

nah thats not the problem

#

i believe

devout coral
#

Where on there are you specifying which forms to use?

late gale
#

let me send it to you

devout coral
#

No, in the view

#

Which line are you telling it which form to use

late gale
#

fields

devout coral
#

Because UpdateView creates a form for you based on the model you pass it.

#

Unless you tell it which for to use

late gale
#

i added the fields so it knows what forms to use

devout coral
#

Ok in you template do the following please.

Remove everything in the form tag and add {{ form }}

late gale
#

ok

#

they are showing but in weird way

devout coral
#

Yeah.

#

Because by default it will pass the form as form.

#

Now un comment the first field and replace it with the following. {{ form.position|as_crispy_field }}

late gale
#

ok let me try

#

oh it's showing

#

but the reason is why

#

why profile not showing but form is

devout coral
#

Ok let me explain

#

So basically by default UpdateView just takes a model and it will automatically create the form for you then pass it to the template as form. So you can access it in you template like so: {{ form }}

#

You can however make a custom form and tell the view to use it and also give it the name for the variable.

#

But it looks like You havenโ€™t done either of those things.

late gale
#

ok here is another problem

#

i tried to view the update page from the second user but i believe that this user is not showing because the user.id is different than the profile's id not worked as the superuser which is me

#

it gives this error

#

i am really sorry for asking too many questions

#

let me see

devout coral
#

No problem at all.

#

I will be leaving soonish though.

#

So what is not working?

late gale
#

i beleive the problem is here

    {% if request.user.is_authenticated  %}
    <a href="{% url 'Update_Profile' user.id %}" class="btn btn-danger" style="position: relative; top: -50px;">Edit</a>
    {%else%}
    {% endif%}
devout coral
#

Yes, user.id will correspond to whoever is logged in.

late gale
#

let me try

#

yea not working

#

let me show u ther error

devout coral
#

Show me your urls too please

late gale
#

sure

#
    path('<int:pk>/profile/',user_views.UserProfile.as_view(), name='Profile'),
    path('<int:pk>/profile/update',user_views.UpdateProfile.as_view(), name='Update_Profile'),
devout coral
#

Yeah the problem is with what you are passing to the url

#

Ok one sec

late gale
#

fixed it

devout coral
#

Why are you passing the id to begin with?

late gale
#

waait

devout coral
#

Ok, how did you fix it?

late gale
#

i added this user.profile.id instead

#

as each user has profile and it gives the profile id to the url

#

as every user has different user id and different profile id

#

let me check on everything again

#

so we are done here

devout coral
#

So y out got it?

late gale
#

yeea thank you alot

#

i am checking now on everything

#

got a problem

#

xDDD

#

lol

#

{{ form.user.email|as_crispy_field }} the email is not passing

#

everything works except the email

devout coral
#

So remove crispy stuff see what you get

late gale
#

i need to add the email to the field i guess and add it to the forms.py

#

i got nothing

#

so how can i add the user's email to the field where its from different class

vivid canopy
#

hey guys wanna ask about css if i can position linear gradient in background?

devout coral
#

@late gale you would need a custom form and probably add to its save method.

#

@vivid canopy you can

#

@vivid canopy just set the background color using linear_gradient.

late gale
devout coral
#

@late gale are you using the Django default user?

late gale
#

nope

vivid canopy
#

ty guys gonna look at it

late gale
#

a user i created from the form

devout coral
#

@late gale No I mean the actual model itself

late gale
#

the account that i am currently logged in ?

devout coral
#

No, Im your models. How are you defining your user class?

late gale
#

there

#
class UserRegisterForm(UserCreationForm):
    email = forms.EmailField()
    class Meta:
        model = User
        fields = ['username', 'email','password1', 'password2']


# USER UPDATE FORM!!
class UserUpdateForm(forms.ModelForm):
    email = forms.EmailField()
    class Meta:
        model = User
        fields = ['username', 'email']
#

i wanna get that email from that class UserUpdateForm

devout coral
#

Ok I get that. But I think you should just have email as part of the user object. Along with the username.

#

Why not do that? This way you only have to worry about that one object when dealing with a users information.

late gale
#

elaborate please

devout coral
#

Plus it will make your view a lot easier.

late gale
#
from django.db import models
from django.contrib.auth.models import User

class Profile(models.Model):
    user = models.OneToOneField(User, on_delete= models.CASCADE)

    bio = models.TextField(max_length=300)

    Committees = (
        ('IT','IT'),
        ('Design','Design'),
        ('ER','ER'),
        ('Design','Design'),
        ('Marketing','Marketing'),
        ('Coaching','Coaching'),
        ('Media','Media'),
        ('Branding','Branding'),
    )
    committee = models.CharField(choices=Committees, max_length=10, default='')

    position_list = (
        ('Member', 'Member'),
        ('Head', 'Head'),
        ('Vice', 'Vice'),
        ('President', 'President'),
    )
    position = models.CharField(choices=position_list, max_length=10, default='Member')

    awards = models.TextField(max_length=300, null= True)

    experience = models.TextField(max_length=300, null=True)

    achievement = models.TextField(max_length=300, null=True)
    
    image = models.ImageField(default='default.jpg', upload_to='profile_pics')

    def __str__(self):
        return f'{self.user.username} Profile'
        
#

there

devout coral
#

Can you paste bin it. Iโ€™m on mobile and makes it easier to read a lot of code.

late gale
#

oh sure

#

there

devout coral
#

Thanks

#

One sec

#

Alright, yeah so you are just making a profile and having a OnetoOne relationship with profile. Now this is ok for something quick a dirty. But what you probably should be doing (specially to make your life a lot easier later) is to make a custom user model.

#

One that inherits from AbstractBaseUser

#

It sounds complicated and it really isnโ€™t. This will allow for you to simply make one UpdateView pass it the user class(the custom one) and that is it. No need to make a form or anything.

late gale
#

so you mean i have to create a user custom model instead of the default one ?

#

but i don't want that it will change the regisration and the adminpage and everything doesn't it?

devout coral
#

Yeah it will.

#

I do not think you can have two separate forms in UpdateView.

#

Iโ€™m not sure though.

#

You can just make your own class view to handle the two different forms.

late gale
#

btw i believe {{form}} is not the correct method

#

when i say {{form.user}} it shows me the users who has a profile but what i wanted is a form that can change his username

#

let me see

devout coral
#

Yea, because it will not create a second form...

#

Thatโ€™s what I am trying to say.

#

UpdateView is for one model. To update one Model.

late gale
#

what shall i use then

#

formview ?

#

let me try

devout coral
#

I think there is a multi form view class

late gale
#

nope there isnt

vivid canopy
#

sry mb bad said question i wanted to do this gradient colors to like rotate like whole that color section

late gale
#

no there is not @devout coral

devout coral
#

Alright, so make your own class to have two forms and save the results.

#

However, I think you are better off making a custom user.

late gale
#

let me see something

devout coral
#

@late gale well good luck, message me if anything but I might not be able to respond.

late gale
#

thanks i am trying to see another way

#

trying to work the update button

devout coral
#

Alright, also once y py solve it. Iโ€™d like to know how you did so let me know (ping me)

late gale
#

thanks ^^

swift trout
#

don't worry getting there

late gale
#

@devout coral hey i found that update button only works without crispy fields but i want it to work with crispy fields so i can use css and js

#

here is the template

#

idk why

#

like really why doesnt the button work

unborn dust
#

hello
let's talk about why is elasticsearch, (django-elasticsearch-dsl) being a PITA today
so I have a nested field on my model, which is being populated, and has it's mapping type defined
and every time the index updates, that fields gets disappeared ๐Ÿ™‚
i cant figure out why it keeps happening

devout coral
#

@late gale manually bind it to the form. Set the id property for the form. Then set the form property for the button to the same as the formโ€™s is

late gale
#

what do you mean

#

elaborate please

#

@devout coral

devout coral
#

@late gale like so:

<form action=โ€œโ€ id=โ€œsomeFormโ€>
        <button type=โ€œsubmitโ€ form=โ€œsomeFormโ€>Submit<\button>
<\form>
late gale
#

oh so they both have the same id?

#

ok

#

let me try

devout coral
#

No, the form has an id then you set which button the submit goes to with the form property.

#

Sorry, on mobile. Had to edit.

late gale
#

still not working

devout coral
#

Is it not submitting?

late gale
#

yes its not

native tide
#

I don't think you need to set the form attribute for the button for it to be linked to a form.

#

Btw what is the original problem?

late gale
#

the button doesnt submit

devout coral
#

@native tide you donโ€™t.

#

Just testing

#

@late gale try manually setting the forms action to the url.

native tide
#

form method="post"

#

do that

late gale
#

still

devout coral
#

@native tide that should not matter. I use POST all the time.

#

@late gale did you try setting the action url?

late gale
#

let me try

#

it says page not found

#

let me show you the code

devout coral
#

Well itโ€™s submitting now

#

Did you use the url tag?

native tide
#

Yeah I don't see why it wouldn't be submitting.

#

You can see if it's making POST requests, is it?

devout coral
#

It just did. They set the action on it and it posted. Now they are getting page not found error.

native tide
#

Yeah so thats not the issue

late gale
#

wait let me see

devout coral
#

It was not posting before now it posted.... it was no?

late gale
#

not submiting

#

it only submitted while i changed use this instead idk why

devout coral
#

@late gale did you not just get a page not found error? How did you get that without posting?

native tide
#

what leads you to think it's not submitting

late gale
#
{% extends 'base/base.html' %}
{% load crispy_forms_tags %}
{% load static %}
{% block content%}
<div class="profile-body">
    <header>
        <div class="container">
          <div class="col mt-5">
            <form method="POST" enctype="multipart/form-data">
              {% csrf_token %}       
              <div class="form-group col-md-4 mb-0" >
                {{ form|crispy}}
              </div>

                    <button type="submit" class="btn btn-danger ">Update</button>
                    
                </form>
              </div>
        </div>
    </header>
</div>

{% endblock content%}
#

Whenever i used this the button submit

#

otherwise not

devout coral
#

@late gale set the action property on the form and try it.

native tide
#

forms can be in the header?

late gale
#

@native tide the page keeps refreshed while it should redirect me to the profile page with the new updates

#

i did set an action and didnt

#

let me show you

#
            <form method="POST" enctype="multipart/form-data" action="{% url 'Update_Profile' profile.id %}">
              {% csrf_token %}   
              <div class="form-group col-md-4 mb-0" >
...
native tide
#

so when you submit that form, what is the URL it's trying to redirect to (you should see this in your logs)?

late gale
#

shall i set the action="" to the link that should be redirected too ?

#

let me try

devout coral
#

No, just look at the terminal where the server is running for the post request being sent.

native tide
#

well the action attribute redirects you to the specified URL when you submit the form. And as said ^ you can see where it's trying to redirect you

late gale
#

i did set the action to the redirected page but it shows me white screen

#

i believe that means that the button is not submitted

native tide
#

You submitted the form and it redirected you, so it did submit. You could've just checked your logs and see that it's making post requests

devout coral
#

What are you logs showing? Where you ran python manage.py runserver

#

It should tell you which url it went to which can tell you which view it is trying to use

late gale
#

guys just listen the button submit here

{% extends 'base/base.html' %}
{% load crispy_forms_tags %}
{% load static %}
{% block content%}
<div class="profile-body">
    <header>
        <div class="container">
          <div class="col mt-5">
            <form method="POST" enctype="multipart/form-data">
              {% csrf_token %}       
              <div class="form-group col-md-4 mb-0" >
                {{ form|crispy}}
              </div>

                    <button type="submit" class="btn btn-danger ">Update</button>
                    
                </form>
              </div>
        </div>
    </header>
</div>

{% endblock content%}

and it doesnt submit in my template

#

although there is no action

native tide
#

When there is no action the page will just refresh. The form will not redirect anywhere

#

What do you mean by "doesn't submit", what are you trying to get from the form?

late gale
#

it will be redirected because i used UpdateView which redirects url when u use get_absolute_url in the models.py

#

i am trying to make the form update the data

upper gorge
#

yo

#

can anyone here help with cyclical import

#

im very new to flask tryna make a blog

native tide
#

Ok so have you set up your view to handle the form data?

#

@upper gorge use blueprints

devout coral
#

@late gale Could you just post the log? So we can see what view it is going to?

upper gorge
#

@upper gorge use blueprints
@native tide i do not understand blueprints, maybe i just gotta sleep on it

late gale
#

ok let me post the log

upper gorge
#

ive been working on the design for well over 4-5 hours today so

#

ill try tomorrow

late gale
#

[07/Nov/2020 23:40:39] "POST /en/16/profile/update HTTP/1.1" 200 13427

#

there

#

the Post request

native tide
#

Yeah when I was learning blueprints I didn't get it either, watch some good explanatory videos on it and practice that helped me. But the blueprints do fix the cyclical imports for sure @upper gorge

#

So yeah, it's submitting

upper gorge
#

Yeah when I was learning blueprints I didn't get it either, watch some good explanatory videos on it and practice that helped me. But the blueprints do fix the cyclical imports for sure @upper gorge
@native tide yeah tysm

late gale
#

then why the data isnt saved and its not redirected

devout coral
#

@late gale so itโ€™s posting and returning a 200 status code. So check that view and look at what template you are trying to render.

native tide
#

@late gale when you submit a form, you need to handle the data in your view (that is where you will save the data). The form does not save it - it just sents data from the client to the server

late gale
#

but when i use this template it does redirects me and saves the form

{% extends 'base/base.html' %}
{% load crispy_forms_tags %}
{% load static %}
{% block content%}
<div class="profile-body">
    <header>
        <div class="container">
          <div class="col mt-5">
            <form method="POST" enctype="multipart/form-data">
              {% csrf_token %}       
              <div class="form-group col-md-4 mb-0" >
                {{ form|crispy}}
              </div>

                    <button type="submit" class="btn btn-danger ">Update</button>
                    
                </form>
              </div>
        </div>
    </header>
</div>

{% endblock content%}
devout coral
#

@late gale wait... you form is rendering properly? You are including crispy form tags but using a crispy filter that does not exist. The syntax should look like the following:

{% crispy form %}
late gale
#

let me try

#

it doesnt show probably

devout coral
#

it doesnt show probably
@late gale ? What does not show?

late gale
#

wait

#

the button is not clickable now and the page doesnt refresh

#

wait

#

oh yes the button isnt

devout coral
#

The button is not what?

late gale
#

submitting

#

and the page isnt refreshing

#

it just clickable

#

even i added an action and still

devout coral
#

But the form is there right?

late gale
#

yes

devout coral
#

And when you click the button nothing shows up in the logs right?

late gale
#

let me see

#

nothing yes

devout coral
#

So now try doing the id thing I mentioned earlier and see if it posts.

late gale
#

ok

devout coral
#

By see if it posts I mean look at the logs to see if anything shows

late gale
#

it worked great but why it doesnt work on the crispy fields

devout coral
#

What do you mean?

#

You are using crispy tag so all the fields are crispy

late gale
#

when i used {{form.bio|as_crispy_field}} the button wasn't working

#

i wanted to adjust every field

devout coral
#

Idk. Now go through and try it.

late gale
#

but it's fine the crispy form looks nice

devout coral
#

And add one field at a time this time

late gale
#

ok let me try the field

devout coral
#

Maybe a field you are passing there is something wrong with it idk.

late gale
#

maybe

#

let me see

#

it doesnt although every form is showing

#

but its fine

#

the crispy form looks nice

devout coral
#

I donโ€™t quite follow.

#

Ok cool

#

Glad you got it

late gale
#

yea thank you @devout coral

#

and thank you alot @native tide

#

I am one of the homies

#

hahaha

vale vault
#

Here is a website i have deployed that uses google auth from a tutorial i followed. It works on local host, but has an issue when i deployed the app to heroku

#

2020-11-07T22:59:02.874765+00:00 app[web.1]: oauthlib.oauth2.rfc6749.errors.InvalidClientError: (invalid_client) Unauthorized

#

That is the error i am getting on my heroku logs

#

It was a typo lemon_hyperpleased

warm igloo
#

as are so many bugs

native tide
#

I can't seem to link my css stylesheet to my React application. Must I use webpack for this?

vast path
#

https://plotly.com/python/v3/html-reports/
Does anyone know of a more up to date stack for generating static html reports, with graphs and stuff? This guide uses python2 so seems kind of out of date, and I'm not really familiar with the area.

torpid pecan
#

Anyone know if you can deploy a python app on Cpanel with bluehost?

#

Im having some troubles

cold haven
#

Hello

#

I used bluehost for WordPress

#

Not sure

#

I didn't host on aws or azure for example because WordPress recommended them as the number 1 hosting for their CMS

torpid pecan
#

Do you have a recommendation for deploying a Django app

cold haven
#

Docker

#

Put it into a docker container and deploy

#

I think I have tutorial saved, brb

#

Take your pick. There are plenty of tutorials online

torpid pecan
#

Are you only able to host a Django app on a VPS server? not shared.

rough silo
#

Anyone recommend a good resource for learning/setting up a user account system in flask?

near bison
#

Flask tutorial by corry schafer might work.

#

Is the stuff like tax percentage stored in the db ? it's a single value (ex 2%) ? a non developer should be able to change the value from an interface such as django admin app

tropic rapids
#

I am not understanding the css transition property . Can any one help me to understand it?

native tide
#

can someone explain how to create a login system with flask?

hollow flower
#

JWT login? @native tide

tall bobcat
#

I made this using django rest frame work

https://codestrike.in

CodeStrike.in

CodeStrike is an online programming skills testing platform for employers, hiring managers and computer science students.

#

I will be sharing my git repo in a while, need to clean it up a bit

toxic flame
#

Any tips on how to homehosy django websites? Windows

tall bobcat
#

Get a fast internet,
A kick ass router

Watch a youtube video on how to open your comouters port through your router

It'll be unsafe if there's any valuable data on your system.

You done.

#

@toxic flame

vernal furnace
#

anyone knows a doc where I can find a list of these?

class="btn btn-secondary btn-sm mt-2 mb-2"
vivid canopy
#

hey guys wanna ask what should i have wrong. when i write in cmd python main.py error says there is something wrong with line 32 wich is login line line...for me it looks like login def doesnt take LoginForm but i m not sure

quick cargo
#

it tells you

#

methodds

vivid canopy
#

yeah now i seen it

#

just a minute back saw it but anyway ty

vernal furnace
#

the code is exactly the same

late gale
#

share us ur code

vernal furnace
#
{% extends "blog/base.html" %}
{% block content %}
    <article class="media content-section">
        <img class="rounded-circle article-img" src="{{ object.author.profile.image.url }}">
        <div class="media-body">
        <div class="article-metadata">
            <a class="mr-2" href="#">{{ object.author }}</a>
            <small class="text-muted">{{ object.date_posted|date:"F d ,Y" }}</small>
            
            {% if object.author == user %}
                <div>
                    <a class="btn btn-secondary btn-sm mt-1 mb-1" href="{% url 'post-update' object.id %}">Update</a>
                    <a class="btn btn-danger btn-sm mt-1 mb-1" href="{% url 'post-delete' object.id %}">Delete</a>
                </div>
            {% endif %}
        </div>
        <h2 class="article-title"> {{ object.title }}</h2>
        <p class="article-content">{{ object.content }}</p>
        <a class="btn btn-light btn-sm mt-1 mb-1">{{ object.bedrooms }}</a>
        </div>
    </article>
{% endblock content %}
#

the form_detail page

#
{% extends "blog/base.html" %}
{% block content %}
    {% for post in posts %}
    <article class="media content-section">
        <img class="rounded-circle article-img" src="{{ post.author.profile.image.url }}">
        <div class="media-body">
        <div class="article-metadata">
            <a class="mr-2" href="#">{{ post.author }}</a>
            <small class="text-muted">{{ post.date_posted|date:"F d ,Y" }}</small>
        </div>
        <h2><a class="article-title" href="{% url 'post-detail' post.id %}">{{ post.title }}</a></h2>
        <p class="article-content">{{ post.content }}</p>
        <p class="btn btn-light btn-sm mt-1 mb-1">{{ object.bedrooms }}</p>
        </div>
    </article>
    {% endfor %}
{% endblock content %}
#

the home page

#

I just changed the <a> to <p> so no worries

nova nacelle
#

I just changed the <a> to <p> so no worries
@vernal furnace solved?

vernal furnace
#

no

#

I FIXED IT!

#

The problem was object.bedrooms, object.bedrooms was a class that only worked for certain forms, it wasn't supposed to work on home.html, so the solution was post.bedrooms

vernal furnace
#

nvm

#

<hr>

modest shale
#

Guys

#

i need helo

#

help*

#

someone can help me ??

#

i get this error

#

init() takes 1 positional argument but 3 were given

#

init has underscore

sleek hare
#

Can you send the whole error (with traceback)?

vernal furnace
#

I downloaded open iconic from bootstrap

#

anyone knows how to use it/download it to my project?

tardy heron
#

should i send a query string or json with PATCH request?

coral wind
#

can i set the target attribute of a form button to a value so that submiting the form will not change the window

#

so that i can send a POST request to say website/api and stay on website/index

native tide
#

where does my django project saved in windows?

#

also How do I move the folder to docs by which all my projects will save in docs

#

If I make a POST request to submit HTML to my database, will it be saved as HTML or as plain text?

#

@coral wind yeah you can do that, it's easy to do with JS

coral wind
#

window.location.replace() is the answer

#

if anybody wants to know

native tide
#

do any of you guys know how to change the location where my django projects are saved in windows?

vivid canopy
#

hey guys wanna ask what he did in the cmd at 16:10 like how did he get that long path https://www.youtube.com/watch?v=8aTnmsDMldY&ab_channel=PrettyPrinted

In this video, I show you a more realistic example of how to use Flask-Login, Flask-WTForms, Flask-SQLAlchemy, and Flask-Bootstrap to build a registration and login system for users of your Flask app.

This is something that is very common to web apps, so if you need to know h...

โ–ถ Play video
native tide
#

what long path @vivid canopy

vivid canopy
#

like what he did there bcs when ctl+c to stop runing local host

#

and write sqlite3 database.db

#

""" 'sqlite3' is not recognized as an internal or external command,
operable program or batch file. """

#

this is what i get

#

i m right now looking for instalation it but idk if it will work

#

@native tide if u understand what i mean

severe venture
#

ValueError: malformed url rule: '/stats/<string:date:>/<string:tier>-1500'

trying to use flask to setup an api, and im getting this error. this is the line where I add the resource:
api.add_resource(Stats, "/stats/<string:date:>/<string:tier>-1500")

why am I getting this error?

devout coral
#

@severe venture I donโ€™t use Flask but you use the word string to signify you need a string? As opposed to str.

severe venture
#

yes, its the whole word

devout coral
#

Ok cool.

#

After date there is another colon, thatโ€™s supposed to be there?

severe venture
#

oh man

#

its always something stupid isn't it

#

good catch

devout coral
#

Lol no worries. Glad I could help

vivid canopy
west hollow
#

Hey
Anyone onine?
Can anyone help me
I am facing issue in getting in ssl certificate
for the website

vapid fox
#

What is the issue?

#

@west hollow

west hollow
#

idk how to get it

#

@vapid fox

vapid fox
#

You want to create an ssl

#

certificate?

#

@west hollow

west hollow
#

Yes sir

vapid fox
#

Have you tried cloudflare ?

#

They provide free

#

and easy to setup

#

ssl protection

#

@west hollow

vivid canopy
vapid fox
#

I think that u forgot a quote

#

at

#

the end

#

single quote

warm igloo
#

yup

#

about to say that

vapid fox
#

well i said it first

warm igloo
#

haha

#

point to @vapid fox !

vapid fox
#

yes

#

i need credit

warm igloo
#

๐Ÿ…

devout coral
#

Hello everyone

warm igloo
#

Good morning (where I am)

vapid fox
#

good morning

devout coral
#

Yโ€™all currently working on some Web Dev projects?

warm igloo
#

always

vapid fox
#

yes

vivid canopy
#

@vapid fox that moment when i cant figure it out for 2 hours and seen just missing ' ....ah it feels like to go trough mi heart with knife

vapid fox
#

hahaha

#

you do get used to the error messages.

#

in this isntances it is telling you that it

devout coral
#

What projects are you guys working on? If you donโ€™t mind me asking?

vapid fox
#

read the end of file

#

without being able to finish reading the string

#

( i.e. didn't find the end of the string )

#

@devout coral I am working on building

#

an appstore

#

for emacs

vivid canopy
#

anyway ty ....now i know and will know to future for long time D

warm igloo
#

Tweaking some stuff on warcache.com a little wargaming site I built a while ago. Also turning its Flask skeleton into a cookie-cutter template.

devout coral
#

Nice nice

vapid fox
#

wbu?

devout coral
#

This second I donโ€™t have access to my computer so im a bit bored. But I am working on a web app. Currently working on getting it all into docker to increase productivity and help during deployment.

vapid fox
#

What is the web app about?

native tide
#

hi

#

i accidently deleted a postgresql table created by django

#

how to fix the issue ?

gentle crown
native tide
#

fixed it

nova nacelle
#

fixed it
@native tide I wanna know how.

indigo moth
#

I have asked a question in #help-broccoli, about Django and React integration, I get unexpected 404 error, if you wanna help please see the question in channel for more details

coral raven
#

I need ideas to make flask projects. Any ideas?

indigo moth
#

try replicating things like Reddit or Twitter

native tide
#

used magic powder Spโˆ†rtn
#4575

late gale
#

this line gives me this error why??

return reverse('Profile', kwargs={"pk": request.user.id })
#

oh fixed it

#

thanks

halcyon lion
#

can you guys think of a reason why css wont load on the new page when i use extend? I tried to copy/paste the whole html code and still its not loading the css on the new page

quick cargo
#

cache

native tide
#

@halcyon lion CTRL + F5 in the browser

halcyon lion
#

๐Ÿ˜

native tide
#

uhmm, ok. That is something that a lot of people stumble upon, so what is your issue?

halcyon lion
#

It's just baffling how the same html copied on another html file is not working

#

So I wanted to extend the page using header and footer from base page and get a register form in the middle

#

I loaded static

#

I did everything and it doesn't load any css for the base.html

waxen pilot
#

Any recommendations on how to write the front end for a tornado service that is controlling a piece of hardware? I've cobbled together a working HTML/websocket implementation, but it is pretty rough, and would like it to be a bit more uniform and easier to change.

warm igloo
#

@halcyon lion So, anything in the browser console? Like maybe a 404 for the css file? Check the path, maybe something isn't as you think it is.

rare zinc
#

can someone help me with web scraping

#

how do I do that

#

im pretty new to python, like 1 or 2 weeks but i need this for a project in my comp tech course

hollow flower
#

Can someone please tell me if this is incorrect? At least if i do use that validate request function, the request fails even from Twilio.

from django.core.exceptions import SuspiciousOperation
from django.http import HttpRequest, HttpResponse
from django.conf import settings
from django.utils import timezone
from django.shortcuts import reverse
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
from twilio.request_validator import RequestValidator
from twilio.twiml.voice_response import VoiceResponse
from .settings import twilio_auth_token
import arrow


request_validator = RequestValidator(twilio_auth_token)


def validate_django_request(request: HttpRequest):
    try:
        signature = request.META['HTTP_X_TWILIO_SIGNATURE']
    except KeyError:
        is_valid_twilio_request = False
    else:
        is_valid_twilio_request = request_validator.validate(
            signature=signature,
            uri=request.get_raw_uri(),
            params=request.POST,
        )
    if not is_valid_twilio_request:
        # Invalid request from Twilio
        raise SuspiciousOperation()
swift sky
#

can i do conditionals using flask-wtf/wtforms?

#

like if i have a survey, ive only seen the form class defined as a set of variables, but can i do like "conditional values" for my form traits

#

like if input = yes, class has variable Y

#

or should that be handled in my view function?

solid karma
#
    @app.errorhandlder(404)
AttributeError: 'Flask' object has no attribute 'errorhandlder'```
#

why is this happening?

#

so confused

next rock
#

I'm trying to deploy flask on namecheap,
currently I set the logfile location like this:

logfile = os.path.join(os.path.dirname(__file__), "app.log")
print(logfile)
if not os.path.isfile(logfile):
    with open(logfile, "w+") as f:
        pass
logging.basicConfig(level=logging.DEBUG, filename = logfile)
t = time.ctime()
app.logger.info(f"Started at {t}")

however when I do this the file remains empty even though it is properly created. any ideas?

#

(btw it works locally)

#

also everything else works fine like file serving / content generation

severe burrow
#

w+ means create a new file every time its launched

#

so it might just be getting wiped out

#

is that all of the relevant logging code?

next rock
#

yes but the new file only gets created if it doesn't already exist

#

even when just that logging code runs it should have the "started at" entry

native tide
#

Why not โ€œaโ€ instead of โ€œw+โ€?

#

What python version are you running on namecheap?

#

Needs to be 3.6+

#

yo im having a problem with selenium (python,windows 10): so this is an element that im using in my code:
'//*[@id="itemCardmarket_0"]/text()' and there is text embedded within the element but since it has that "text()" end part i cant print the text thats in the element, so how would i change it to where i can print the text of my element even with the "text()" thing at the end?

native tide
#

can I use flask to hook my code with a website

#

ok ty

#

or is there any way to do that?

#

thanks

vestal hound
#

can I use flask to hook my code with a website
@native tide what do you mean

native tide
#

Like if a user clicks on something it triggers my code

#

lime

#

Like

vestal hound
#

yeah that's basically what Flask does

#

when the user visits a URL

#

it triggers a function

#

in your Flask app

native tide
#

From

top.gg
If someone clicks on a button it

print("hi you clicked on the buttor on the website called top.gg)

#

the already built websites

#

Or taking pictures from reddit

strong umbra
nova nacelle
#

i want to center my couresel but i cant ??
@strong umbra What have you tried to center it?

#

@strong umbra I mean what didn't work?

torpid pecan
#

Can anyone recommend a good YouTube series to learn the basics of creating a web application from scratch

nova nacelle
#

Can anyone recommend a good YouTube series to learn the basics of creating a web application from scratch
@torpid pecan Which framework do you wanna learn?

torpid pecan
#

@nova nacelle Django

nova nacelle
torpid pecan
#

Awesome thank you

twilit needle
#

hello

#

So I am using Django forms alongside Html

#

when validation if the form isnt valid then all the content of the form is reset

#

this is what I have like the error is issued but then the content previously entered is reset

#

how to prevent this?

#

pls ping me when help

#

thanks!

#

views.py

def register(request):
    if request.method == 'POST':
        register_form = RegisterForm(request.POST)
        if register_form.is_valid():
            register_form.save()
            # redirect to homepage after registration
        else:
            pass
    else:
        register_form = RegisterForm()
    return render(request, 'register.html', {'form': register_form})```
#

this is how I check for errors and validate the form

twilit needle
#

anyone there??

frozen python
#

I have a VSCode โ€œtaskโ€ that create a Django project for me. BUT, how do I add a choice to enter in what to name the project? So: && input=โ€œ name here โ€œ? How do I add a โ€œquestionโ€ of what name I want to give it?

rustic pebble
#

Hi, I am getting the following error:

This typically means that you attempted to use functionality that needed
an active HTTP request.  Consult the documentation on testing for
information about how to avoid this problem.
#
def paid_redirect(f):
    @wraps(f)
    def decorated_function(*args, **kwargs):
        user = User.get_from_cookies()
        key = Key.get(user.key)
        if key.is_active():
            return redirect('/dashboard')
        return f(*args, **kwargs)
    return decorated_function()
    @classmethod
    def get_from_cookies(cls):
        user_data = Authentication.get_cookie_data('user_d')
        if not user_data:
            return None
        if 'discord_id' in user_data.keys():
            user = User.get(discord_id=int(user_data['discord_id']))
            if user:
                return user
        return None
    @classmethod
    def get(cls, key_value: str):
        key = Key.query.filter_by(value=key_value).first()
        return key
    def is_active(self):
        return True
    @classmethod
    def get_cookie_data(cls, name: str = None):
        if not name:
            raise Exception('NoneType: invalid cookie name "None"')
        token = request.cookies.get(name)
        return Authentication.decode_jwt(token)
#
    @classmethod
    def decode_jwt(cls, token: str = None):
        if not token:
            raise Exception('NoneType: a token has not been passed')
        token = str(token)
        data = jwt.decode(token, Authentication.__readfile__('./assets/keys/jwt-key.pub'))
        return data.decode('utf-8')
#

I hope anyone can help me ๐Ÿ˜„

rapid bramble
#

Any ideas why subprocess doesn't work inside uWSGI?

native tide
#

@twilit needle if the form does not send render it again with request.POST

topaz finch
#

Is it possible to run an Aiohttp websocket on a flask app? And if so, how? @ me when responding please.

quick cargo
#

@rapid bramble probably cuz uwsgi is not allowing child processes in order to ensure process management

#

@topaz finch is it possible? Yes, should you do it -> Fuck no

rapid bramble
#

Hmm I see, nvm I switched to gunicorn and did a bit of code tweak

#

Works perfectly now ๐Ÿ˜„

topaz finch
#

@topaz finch is it possible? Yes, should you do it -> Fuck no
@quick cargo why would you recommend not doing it?

quick cargo
#

because you're mixing a Sync framework with a async system

halcyon lion
#

help ๐Ÿ˜„

native tide
#

give me some ideas for django ..

viral matrix
#

ecommerce

topaz finch
#

@quick cargo so my websocket server is going to be connected to a client application. The intention is essentially to make interaction quicker. Currently, the flask app would have to make http requests to the websocket server to receive info from the other app, and to give it info. If I connected the flask app as well, it would essentially just be to receive some basic data from the other application, and to send info to the other app, in a way that wouldnt involve http requests. Essentially, just replacing http requests w/ websocket requests. I can do either, just thinking that having both ends connected to websocket server would be nice. How would I go about doing it either way, can you point me in the direction so that I can do more research on this as well?

@ me when responding, and thank you for your time and feedback.

quick cargo
#

then rewrite it in async using a async lib. Flask is slow same with Django no way to get around that. @topaz finch

topaz finch
#

That would not be a small process ๐Ÿ‘€

rustic pebble
#

@topaz finch You can use Quart which is almost identical to flask

#

And its async

topaz finch
#

how hard would conversion be? This is not a small app.

rustic pebble
#

It will take time

topaz finch
#

would this mostly be replacing decorators and such, or..

#

hmm

rustic pebble
#

It will mostly be replacing decorators and things, but some core processes are done differently since it is async

#

What app are you building?

topaz finch
#

What types of speed increases are we talking about here? I will look into a full replacement, but if not, I may at least replace my API with async webapp.

rustic pebble
#

I am not sure wha toyu want to do

#

Are you looking to communicate between 2 webservers?

native tide
topaz finch
#

@rustic pebble No, flask web server an an async bot application.

rustic pebble
#

You mean a discord bot?

#

@topaz finch

topaz finch
#

yes

rustic pebble
#

Haha

#

You can do the following:

#

Run the bot and an async quart server on the same loop, that way you can communicate with the flask server with no problem

#

and its really easy as well

#
    loop = asyncio.get_event_loop()
    loop.create_task(client.start('token_here'))
    app.run(loop=loop, port=3000, host='0.0.0.0')

That simple ^^

#

Then divide the client and the app into different folders and work on them independently

#

That way you can have a setup like this:

topaz finch
#

I am admittedly new to the world of asyncio and aiohttp. So far I have been using an.. unconventional and bootleg way for website -> bot communication, which is why I am making this websocket. Even the current way will vastly improve communication, but just checking if there is anything else I should do.

Well wouldnt that still involve http requests?

rustic pebble
#

Why do you consider http requests

#

bad?

topaz finch
#

I dont really. Http requests to communicate w/ my bot are way better than my last method

rustic pebble
#

Http requests are really fast

#

For this sort of thing

topaz finch
#

right

rare zinc
#

can someone help me out with web requests
i wanna get info from bazaartracker.com and use the values for a, b, and c variables but idk how to

#
choice = str(input("What Minion do you wish to calculate the price of?   >>>   "))

if choice == "wheat":
    a = float(input("What is the price of wheat?  >  "))
    b = float(input("What is the price of hay bale?  >  "))
    c = float(input("What is the price of enchanted haybale?  >  "))
rustic pebble
#

I am not really sure of the size of your project

#

But I have done some pretty big projects usingt hat method

quick cargo
#

dont run a bot and a webserver in the same process ๐Ÿ˜ฉ

topaz finch
#

Ill look into quart, because you are right in that it looks VERY similar to Flask, and your method certainly has merit. If I had known about it in first place I probably would have started there, but I also already have the websocket server and client partially set up and tested, so it just depends. I sincerely appreciate your time on this, and all the feedback, it has been enlightening. I think I will replace at least some of my current flask app w/ Quart, because just from basic lookup it seems like itll be faster.

quick cargo
#

Quart is litterally a drop in replacement other than the async await keywords

#

but yeah

rustic pebble
#

dont run a bot and a webserver in the same process ๐Ÿ˜ฉ
I used to to think that as well

#

But for like

#

really simple http requests you can use it

quick cargo
#

but by that point its easier to just run it seperately

rustic pebble
#

Although you can tap directly into discord and not use the http thing

quick cargo
#

and use a gateway or smth

rustic pebble
#

No, its not easier

#

Trust me

#

Its a 3 line thing

#
    loop = asyncio.get_event_loop()
    loop.create_task(client.start('token_here'))
    app.run(loop=loop, port=3000, host='0.0.0.0')

That simple ^^

quick cargo
#

ik it is but it doesnt mean you should ๐Ÿ˜ฉ

rustic pebble
#

I know its not best practice

#

But it does its work

topaz finch
#

Well my current websocket system allows for my flask app to easily make requests for information and such from the bot, and serve them very quickly in the same http request. I have a framework partially set up for events from flask to my bot as well, so I think I am going to continue on that.

rustic pebble
#

@topaz finch You know you can tap directly into discord api rgiht?

#

Thats what the bot does anyway

topaz finch
#

yes

quick cargo
#

and also yeah what kiwi said

topaz finch
#

I am aware that discord.py makes its own websocket connection, have done a lot of browsing through it while ive been going through this process.

rustic pebble
#

Take some time reading the docs

quick cargo
#

thats not the same as what i just linked btw

rustic pebble
#

You can also do it through http

topaz finch
#

A discord bot using http requests

rustic pebble
#

No

quick cargo
#

meanwhile im sat here with a custom gateway ๐Ÿ˜Ž Website and Bot bot seeing the same thing

rustic pebble
#

You can scrape the discord bot entirely

#

and tap into the discord api directly

quick cargo
#

aka what patreon do to add roles to people

rustic pebble
#

What you can do to do pretty much everything

#

Its dead easy

topaz finch
#

Thonk the discord http api isnt as powerful as gateway tho from what ive seen. Not as many options. But I dont know why I have not considered directly tapping into the gateway from the flask app itself tbh. THough either way I still need the bot and website to communicate, as the website serves as a basic dashboard for server owners as well, so I need to send those settings to the bot itself.

rustic pebble
#

the discord http api

topaz finch
#

@rustic pebble ik because I already use the http api for discord

rustic pebble
quick cargo
#

the majority of the discord api is via HTTP

#

only events are via WS because they have to be

rustic pebble
#

true

topaz finch
#

right

quick cargo
#

balancing WS are way hard to manage than HTTP which is why the majority of stuff is done with HTTP where they can

topaz finch
#

true.

rustic pebble
#

Because websockets are a lot, lot lower level than http reqs

quick cargo
#

eh not really

#

but they're mostly stateful which is ๐Ÿ˜ฉ

rustic pebble
#

You can make an http request with a websocket

quick cargo
#

websockets are http requests

#

just with a upgraded connection to keep the socket alive

rustic pebble
#

and more they need extra headers

#

and shit

quick cargo
#

not really

rustic pebble
#

fuck that, websockets suck, only for live chat

topaz finch
#

um they can definitely be helpful in many situations tho

quick cargo
#

websockets technically after they've been established require alot less than http requests which is why theyre generally quicker

rustic pebble
#

Yes

#

I have never really ever needed websockets too much, I have done huge projects and none of them explicitly required websockets, although in some cases for UX websockets were better

topaz finch
#

Ill definitely do more research based on everything you guys have mentioned, I appreciate the advice

rustic pebble
#

np

lofty matrix
#

Hi, I have some miscellaneous questions about production file uploads that I haven't been able to find an answer for.

Say you have a form with 2 inputs. One takes an image that is less than 1MiB and a video that is less than 250MiB.

  • Should I use client side validation to confirm the file sizes, server size validation of the file sizes, and also set the endpoint max upload size in the webserver configuration to say 252MiB?

I want the image to be 1920x1080 or smaller. I could do client side validation on the resolution, accept the file upload, if it passes the webserver file size check, check the resolution, then return an error if the image is larger than this limit, but I want to allow the user to upload a larger image, and have the web app handle shrinking it.

  • How do I ensure that after the resize operation, the resulting file is under 1MiB?
  • How should I determine the max dimension for me to try resizing? If the user tries to resize a 10000x10000 image that is under 1MiB (like an all-white PNG), my server will run out of memory.
  • How do I account for the possability that multiple users could trigger image resizes at the same time, using up a lot of memory? Do I need to queue these operations somehow?

For the video, I want to be able to serve the uploaded video to other users and have them be able to play it correctly. I can validate the size and extension, but there is a lot of weird codecs/tracks/pixel formats that you can put into .mp4 files that will make the video not play correctly on almost any device

  • Do you pretty much always need to re-encode user-uploaded videos?
  • How do I make sure that the video will not cause memory issues when I try to resize it?
  • How do I account for the possability that multiple users could trigger video re-encodes at the same time, using up a lot of memory? Do I need to queue these operations somehow?
#

These all seem like issues that sites like Facebook/Instagram/Twitter would all need to be dealing with, but I can't find answers to these question online. Any ideas or resource recommendations? Thanks

#

With the image resizing, is that something that should be done client-side instead?

rustic pebble
#
  • Should I use client side validation to confirm the file sizes, server size validation of the file sizes, and also set the endpoint max upload size in the webserver configuration to say 252MiB?
    No, do it server-side, you can pass the metadata if you don't want the user to upload the file to your server since that would increase workload, on the other hand best bet for 100% security that no one is going to upload a 5gb file is that you let them upload it first, analyze it in the server and then come back with a reply, either the file is valid meaning it doesn't exceed your limits or the file is invalid.
  • How do I ensure that after the resize operation, the resulting file is under 1MiB?
    There are modules out there that can compress images to the exact filesize you want, I am missing the names right now but you can find them with one google search for sure

How should I determine the max dimension for me to try resizing? If the user tries to resize a 10000x10000 image that is under 1MiB (like an all-white PNG), my server will run out of memory.
Same way you would do with the file size validation, let him upload it and check it server-side.
You could perform a client-side check but be sure that it can be tampered with

  • How do I account for the possability that multiple users could trigger image resizes at the same time, using up a lot of memory? Do I need to queue these operations somehow?
    You need to create a queue, most webserver frameworks try to stack the requests resulting in a memory overflow thus possibly crashing the server
  • How do I make sure that the video will not cause memory issues when I try to resize it?
    You need to set some limits, you can easily calculate the size of the video and then act accordingly
  • How do I account for the possability that multiple users could trigger video re-encodes at the same time, using up a lot of memory? Do I need to queue these operations somehow?
    Same answer as earlier

@lofty matrix

lofty matrix
#

Thanks @rustic pebble

No, do it server-side, you can pass the metadata if you don't want the user to upload the file to your server since that would increase workload, on the other hand best bet for 100% security that no one is going to upload a 5gb file is that you let them upload it first, analyze it in the server and then come back with a reply, either the file is valid meaning it doesn't exceed your limits or the file is invalid.
My thought around client size + server application side + webserver side size validation is
client side: Instantly gives error if invalid file is uploaded
server application side: If a user is bypassing the client side validation, this would catch, say, a 100MiB image and a 100MiB video upload attempt
webserver side: Avoids hanging the web application in cases where there is no way the content is valid.
Am I thinking of something wrong here?

You need to create a queue, most webserver frameworks try to stack the requests resulting in a memory overflow thus possibly crashing the server
The queue could be full of other work for the next 10 minutes. Do I need to design the application such that this can be done outside of the request-response cycle? (Add the image job the the queue, return a response to the user that says "your image is being processed. Check back later", and eventually have the image resized once it goes through the queue?

quick cargo
#

I wouldnt rely on the front end / client validating size

#

because you can easily get around that

#

and just bypass it by hitting the server directly

#

what you should do is stream the body not read it all at once checking the content-length header if applicable or if it's a chunked encoding method check the chunk size first to make sure it doesnt go over the limit

raw imp
#

I see these images all the time. Do they have a name?
I would like to buy some SVG/PNG versions of these for my website but I don't know what to google....

dapper tusk
#

stock images

native tide
#

@raw imp those images are from undraw

#

or something like that

#

I see them everywhere and it infuriates me

#

you can tell where the image is from... ๐Ÿ’ข ๐Ÿ’ข

dapper tusk
#

You can buy the image if you don't want the watermark

native tide
#

they don't have any watermarks (at least for the ones from undraw). maybe it's just a personal vendetta but I dislike their style

quick cargo
#

@native tide undraw yes

plucky tapir
#

Can someone take a look at my urls in django? When a user is being saved as a foreign key and called on, they are saved as http://127.0.0.1:8000/users/logout/3/ rather than just the username

vivid canopy
#

hey guys wanna do background something like this in video https://www.youtube.com/watch?v=DlUV97e51uc&t=47s&ab_channel=Divinector and have got this (at pic ) any other tuts for some background as is in video?

Very Easy and Simple way to create Skewed / Slanted / razor blade div shape using only HTML and CSS

Follow this Channel on:

Facebook : https://www.facebook.com/Divinector/

Twitter : https://twitter.com/Divinector

Instagr...

โ–ถ Play video
native tide
#

I need to make an API for a web application that will create rooms for multiple users to participate and it will communicate with the clients

#

There would be any notable performance differences between using Flask or Sanic?

#

@plucky tapir Ok, can you paste a code snippet?

plucky tapir
#

@native tide
If there is more needed just let me know

native tide
#

so what is the issue again?

plucky tapir
#

In the url and the django rest api framework pull, the foreign key comes out as an url rather than just the username "bname": "Spotify", "bamount": "10.00", "duedate": "2020-10-20", "user_id": "http://127.0.0.1:8000/users/logout/3/"

#

@native tide but in the database I believe it comes out as the username, or at least the user's ID. Here the 3 is the user ID

vestal hound
#

@plucky tapir show serializer

plucky tapir
vestal hound
#

@plucky tapir HyperlinkedModelSerializer

#

that does exactly what it says it does

#

The HyperlinkedModelSerializer class is similar to the ModelSerializer class except that it uses hyperlinks to represent relationships, rather than primary keys.
(emphasis mine)

plucky tapir
#

@vestal hound Ohh I see, is using hyperlink good practice for django? Also any idea why logout would be in the url anyway? It should function as the 'logout', not sure why its appearing there

vestal hound
#

@vestal hound Ohh I see, is using hyperlink good practice for django? Also any idea why logout would be in the url anyway? It should function as the 'logout', not sure why its appearing there
@plucky tapir depends on what you're doing

#

my API just returns PKs

#

or nested representations where appropriate

#

for your second question

#

look into the documentation of the hyperlink related fields

vagrant oasis
#

hello i am new to web-developement........and i have chosen flask library for a startup......and i always connect it to the localhost to run it......but is there a way to run the website in a complete url.....something like www.webpage/home/................can u do that in flask ???

devout coral
#

You can yes. Once you get to deployment you will want to learn how to do it.

vagrant oasis
#

how to do that

pine bane
#

Hi, I am using FastAPI to create an API. I have a requirement I have to generate an xlsx file and then send an email containing the generated xlsx file download link which can be used to download that file. How can I provide a download link? FileRespose provides a file object what I want is to provide a download link. Any help will be appreciated.

devout coral
#

@vagrant oasis It is probably best to look for a tutorial

vagrant oasis
#

oh tnx i am deploying on heroku.......is that good

twilit needle
#

this thing is annoythin me a lot on django

#

so basically I want to login a user on django like this py def login_request(request): if request.method == 'POST': data = request.POST auth_backend = AuthenticationBackend() login_form = LoginForm(data) if login_form.is_valid(): user = auth_backend.authenticate(data, password=data['password'], email=data['email']) if user: login(data, user) # redirect to homepage else: login_form.add_error('password', "Password doesn't match email") else: data = {} login_form = LoginForm() return render(request, 'login.html', {'form': login_form, 'data': data})

#

however, I get this error that py 'QueryDict' object has no attribute 'session'

#

How can I fix this? pls help me. It would mean a lot

#

thanks!

#
login(data, user)```
#

this is the line causing errors

twilit needle
#

pls someone help me

#

I've asked my question there, too. If someone can help please let them know!!

#

pls I have spent a lot of time on this a solution will really really help me a lot. Please ping me when help

gaunt void
#

Hello, how should I connect this to my host?
I have never worked flask and I do not know how to connect this to my host.
I'm wandering around building a web dashboard and have no information
Please help me

nova nacelle
twilit needle
#

no

#

@nova nacelle

#

not yet..

twilit needle
#

pls somebody help me

jaunty plover
#

hey, how can i use django to create a socket server that could be able to call procedures on a client from the server ?
it has to be launched on init, so when i just add a server like this one : https://pypi.org/project/aiohttp-json-rpc/ in the __init__.py
it starts the RPC server, and block django, not allowing the HTTP server to start

cold haven
#

hi

#

morning

rare zinc
#
import requests
from bs4 import BeautifulSoup

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36'}

page = requests.get("https://bazaartracker.com/product/hay_bale/", headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')

print(soup.find(id='buyprice').text)
#

someone help me out

#

so basically

#

i use this to find the price of smthng

#

and the output is --- instead of the price

#

now sure how to fix it pls help me out

cold haven
#

I have never used == $0 before. What does it mean?

#

in html

#

is that a media query?

#

I didn't know BeautifulSoup could get DOM elements. I have to look into it.

#

no one has an answer I suppose

rare zinc
#

nope

native tide
#
import requests
from bs4 import BeautifulSoup

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36'}

page = requests.get("https://bazaartracker.com/product/hay_bale/", headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')

print(soup.find(id='buyprice').text)

@rare zinc do

#

one seccond

#

do

cold haven
#

I have heard of beautifulSoup, and that's the one I want to use along with one other framework

#

what's the other one that goes with that one to use for webscraping?

rare zinc
#

it still shows ---

native tide
#

soup.find("h2", "class":"buyprice")

#

this should help

rare zinc
#
import requests
from bs4 import BeautifulSoup

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36'}

page = requests.get("https://bazaartracker.com/product/hay_bale/", headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')

print(soup.findAll("h2", "class":"buyprice"))
#

like this?

native tide
#

wait no sorry

#

it's

#

soup.find("h2", {"class":"buyprice"})

#

that should get it

cold haven
#

Web Scraping โ€œWeb scraping (web harvesting or web data extraction) is a computer software technique of extracting information from websites.โ€ HTML parsing is easy in Python, especially with help of the BeautifulSoup library. In this post we will scrape a website (our own) to e...

rare zinc
#

output is none

#
import requests
from bs4 import BeautifulSoup

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36'}

page = requests.get("https://bazaartracker.com/product/hay_bale/", headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')


print(soup.find("h2", {"class":"buyprice"}))
#

@native tide

native tide
#

let me check one sec

#

@rare zinc wait sorry I was doing the wrong thing

#
import requests
from bs4 import BeautifulSoup

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36'}

page = requests.get("https://bazaartracker.com/product/hay_bale/")
soup = BeautifulSoup(page.content, 'html.parser')


print(soup.find("h2", {"id":"buyprice"}))
#

now

#

you just gotta add.text

#

or wait

#

๐Ÿค”

#

I can't find it

#

maybe because the == $0 think

#

@rare zinc

cold haven
#

i think that's a placeholder for input.

#

maybe instead of reading to it you should be writing to it.

native tide
#

I found this

#

so we gotta get the json not the html ig

#

I've never ran into this before so idrk

plucky tapir
#

Django for making a calendar of you upcoming bills what would you guys suggest?

native tide
#

Hey yo guys! i am 15 and i have the basics of programming and fundamentals ready. I want to know which is the best free way to get started and learn web dev

severe venture
#

I am trying to use flask to make an API. It works and can get data from my db (only does GET), but it returns a list of dicts (which I suppose is correct behavior). I want it to return a dict of dicts (or a json of jsons) because i plan to use it for a js app. I want to set the name of each dict to be equal to a field value from the pull.

I start with

[
  {'id_': 669551, 'rank': 153, 'pokemon': 'snorunt', 'usage_pct': 0.07347, 'raw_usage': 104, 'raw_pct': 0.127, 'real': 96, 'real_pct': 0.148, 'dex': 361, 'date': '2020-04', 'tier': 'gen8lc-1500'}, 
  {'id_': 669552, 'rank': 154, 'pokemon': 'milcery', 'usage_pct': 0.0672, 'raw_usage': 108, 'raw_pct': 0.131, 'real': 87, 'real_pct': 0.134, 'dex': 868, 'date': '2020-04', 'tier': 'gen8lc-1500'}, 
  {'id_': 669553, 'rank': 156, 'pokemon': 'cosmog', 'usage_pct': 0.0199, 'raw_usage': 26, 'raw_pct': 0.032, 'real': 19, 'real_pct': 0.029, 'dex': 789, 'date': '2020-04', 'tier': 'gen8lc-1500'}
]

and want to get to:

[
  'snorunt': {'id_': 669551, 'rank': 153, 'pokemon': 'snorunt', 'usage_pct': 0.07347, 'raw_usage': 104, 'raw_pct': 0.127, 'real': 96, 'real_pct': 0.148, 'dex': 361, 'date': '2020-04', 'tier': 'gen8lc-1500'}, 
  'milcery': {'id_': 669552, 'rank': 154, 'pokemon': 'milcery', 'usage_pct': 0.0672, 'raw_usage': 108, 'raw_pct': 0.131, 'real': 87, 'real_pct': 0.134, 'dex': 868, 'date': '2020-04', 'tier': 'gen8lc-1500'}, 
  'cosmog': {'id_': 669553, 'rank': 156, 'pokemon': 'cosmog', 'usage_pct': 0.0199, 'raw_usage': 26, 'raw_pct': 0.032, 'real': 19, 'real_pct': 0.029, 'dex': 789, 'date': '2020-04', 'tier': 'gen8lc-1500'}
]

is there a way to do this natively in flask or will i just have to python it away? (it's not that difficult but, less work is less work)

#

oof sorry for the big post

native tide
#

iss fine

#

but do help me please

severe venture
#

start coding

#

there's loads of free tutorials just google CRUD tutorial and go from there

#

pick one of django or flask (or probably some others) but those are the two most popular

native tide
#

thank you so much!!!!

severe venture
#

flask is pretty simple, django can get in the weeds fast