#web-development

2 messages · Page 84 of 1

nova storm
#

i am creating a whatsapp clone from this website

#

see the codes

#

the frontend is working properly

#

but when i am sending a msg , it doesn't coming on the screen

lyric meteor
#

can you tell me more about your problem? @nova storm

nova storm
#

yes

#

actually i have copied the code from the above link of whatsapp clone

lyric meteor
#

I con't help you with a problem so big, but if you have a specific question i can answer

nova storm
#

and i have created different files for HTML, css, and JS

#

okay!

#

no problem!

lyric meteor
#

oke

quaint bluff
#
    while flag == False:
        snooze = input('would you like to snooze for 10 min? ')
        if snooze.lower() == 'yes':
                     
                snooze_time = datetime.datetime.now().minute
                snooze_time = snooze_time + 1
                if snooze_time == datetime.datetime.now().minute:
                    print(snooze_time)
                    break
        elif snooze.lower() == 'no':
            print(snooze_time)
            break

        elif snooze.lower() != 'no' and snooze.lower() != 'yes':
            snooze = input('would you like to snooze for 10 min? ')```
static night
lyric meteor
#

my bad

static night
#

Or how I can get discord username and profile picture

#

😄

wheat swift
#

does any1 know how to serve static files from nginx?

#

my root is set /var/www/application1

#

must it be a subdirectory?

#

just learned it nvm guys and gals

native tide
glacial tapir
#

do any of you have experience with flask? I am working on making a header for my website and I want to be able to click on it and it to take me to other pages (like and "about" page) but I can't figure out how to make buttons embedded links. Do any of you know anything about how to do that? This is the first thing I've done in flask

ocean gull
#

do any of you have experience with flask? I am working on making a header for my website and I want to be able to click on it and it to take me to other pages (like and "about" page) but I can't figure out how to make buttons embedded links. Do any of you know anything about how to do that? This is the first thing I've done in flask
@glacial tapir I was just gonna send a message about Flask too. I'm curious to know how your website turns out. I have a college project that I have to work on with classmates. We are noobs when it comes to web development.

glacial tapir
#

yeah I've never done web development before so things are going pretty slow

ocean gull
#

There are two YT playlists that do tutorials on Flask. one is codemy.com and the other is by Corey Schafer

versed python
#

yeah I've never done web development before so things are going pretty slow
@glacial tapir I don't have experience with Flask, but I am pretty sure they must have an official documentation. Your specific problem is a common use case, so I'm sure it's mentioned in the Flask documentation.

ocean gull
glacial tapir
#

I've been looking through flask documentation and haven't found anything yet

#

yup @ocean gull that's the official documentation

ocean gull
#

how are you deploying your website? sublime text? Cause I was thinking of using pythonanywhere.com

versed python
#

How would you deploy using sublime text? That is a text editor. > how are you deploying your website? sublime text? Cause I was thinking of using pythonanywhere.com
@ocean gull

ocean gull
#

right. I mean't where is he writing is code on?

versed python
#

do any of you have experience with flask? I am working on making a header for my website and I want to be able to click on it and it to take me to other pages (like and "about" page) but I can't figure out how to make buttons embedded links. Do any of you know anything about how to do that? This is the first thing I've done in flask
@glacial tapir Here you go. url_for('some-route')https://flask.palletsprojects.com/en/master/tutorial/templates/

worn rapids
#

^^^

glacial tapir
#

thank you!

ocean gull
#

I will check it out aswell

worn rapids
#

In this Python Flask Tutorial, we will be learning how to use templates. Templates allow us to reuse sections of code over multiple routes and are great for serving up dynamic HTML pages. Let's get started...

The code for this series can be found at:
https://github.com/CoreyM...

▶ Play video
glacial tapir
#

thank you

strange briar
#

hey guys, can anyone explain me how can i use email to authenticate in django ? I created a class of users based on AbstractBaseUser

class Customer(AbstractBaseUser):
    first_name = models.CharField(max_length=100)
    middle_name = models.CharField(max_length=100, blank=True)
    last_name = models.CharField(max_length=100)
    email = models.EmailField(max_length=255, unique=True)
    phone_number = models.CharField(max_length=20)
    date_of_birth = models.DateField()

    def __str__(self):
        return f"{self.first_name} {self.last_name}, {self.email}"
native tide
native tide
#

@native tide easy

#

use flexbox

#

display flex: Justice-content: center

#

where do i put it?

#

<style>?

#

yeah

#

ok

#

css

#

wut

#

this?

#

no

#

wait

#
.classname{
display: flex;
justify-content: center;
}
#

sorry i annoy

#

nvm i got it

static night
#

@native tide but how I can get discord username etc.?

native tide
#

@native tide but how I can get discord username etc.?
@static night well I use flask-discord (flask) which is easier for what I need to do

#

but with DJango im not sure

distant trout
#

can someone help me fix this? it seems like card itself is moving on hover. I only added in border on hover.. and it still does the same thing without a border

native tide
strange briar
#

Hello how can i make flask serve the backend of react?
here is my repository https://github.com/happyperson10/flaskreact.
if you want to help me ping me.
@native tide You need to make a REST API or a GraphQL, allow django CORS and fetch the data to your react-app from your flask-app
In other words if you don't know anything about these you have a long road of things to learn

native tide
#

alright what should i start with?

#

@strange briar

strange briar
#

at first you should learn djangorestframework

acoustic oyster
#

django rest framework

flask

strange briar
#

and then a JS framework of your choice for front end like axios

#

oh yea indeed

#

he's using flask

acoustic oyster
#

but yes. For my django react app, I allow django to act as ORM and it acts as my api. My React app then receives this data and displays it

#

this is how it should be structured. The front end is React and axios

strange briar
#

Hey NativeLinux maybe you can help me with something

native tide
#

ok thanks guys

strange briar
#

do you know how to implement an AbstractBaseUser in django ?

#

I would like to add more fields to user model

acoustic oyster
#

yeah, what do you need help with?

strange briar
#

and login with email

#

I've done dis

#
    first_name = models.CharField(max_length=100)
    middle_name = models.CharField(max_length=100, blank=True)
    last_name = models.CharField(max_length=100)
    email = models.EmailField(max_length=255, unique=True)
    date_of_birth = models.DateField()

    def __str__(self):
        return f"{self.first_name} {self.last_name}, {self.email}"
#

but i don't know how to setup the login via email

acoustic oyster
#

you can also use AbstractUser instead if you would like all the built in stuff, such as admin, staff, name, email, etc

strange briar
#

Yes but i've seen that it's not good for my case, like adding more fields and stuffs

#

i don't remember exactly why i worked on it yesterday

#

but AbstractBaseUser was the one that would fit my needs

#

AbstractBaseUser also has the authenticate and basic things i would need no ?

#

i'm trying to build an e-commerce website that's why the class is called Customer

acoustic oyster
#

yeah, abstractbaseuser has auth as well.

I recently implemented an AbstractBaseUser in the code jam, we used the default django.contrib.auth.views.LoginView to manage our logins though

strange briar
#

I see

#

and so the login was still done via username and password ?

acoustic oyster
#

yes.

you may need to create a totally custom login form/view that will accept an email and check that the password is correct, then authenticate

strange briar
#

I will make the front with react and graphql

acoustic oyster
#

I am also using graphql 😄

strange briar
#

xd

acoustic oyster
#

this is the exact code, but we are using AbstractUser

def resolve_login(_, info, data):
    request = info.context["request"]
    user = authenticate(username=data["username"], password=data["password"])

    if user is None:
        return {
            "status": False,
            "error": "Invalid username or password",
            "user": None,
        }

    # User is valid
    login(request, user)

    auth_token = generate_user_auth_token(user)
    return {
        "status": True,
        "token": auth_token.token,
    }
strange briar
#

i find it more appealing i learned the basics of rest framework and then i learned also about graphql and decided i would learn and implement this instead

acoustic oyster
#

from django.contrib.auth import authenticate

strange briar
#

thank you 🙂

acoustic oyster
#

graphql is way better imo haha

strange briar
#

interesting

#

yea clearly xd

#

50 endpoints and useless data when you fetch is really meh

#

it's also more friendly to learn tbh

acoustic oyster
#

I hope this helps, I imagine you can replace username with email and it will authenticate?

strange briar
#

yes that's what i was thinking about 🙂

acoustic oyster
#

I found REST easier to learn, but I have been using rest apis for some time, I had never used graphql before working on this project

strange briar
#

I see

#

maybe yes since it's more

#

we can say restraining

acoustic oyster
#

yeah, haha

strange briar
#

like you know what your endpoint is and which data it's gonna provide

#

i'm not very experienced tbh but your example definitely give me some clues so i'll do more researches on this, thank you NativeLinuxUser 🙂

acoustic oyster
#

np, I hope this helps

strange briar
#

yea it does thanks 🙂

hallow jacinth
rare nebula
#

yo idk if this is the right channel but if anyone has experience with regex can you tell me why this

print(re.search("correct_response\">Brazil</em>", "correct_response&quot;>Brazil</em>"))

is coming up with None as the result? I'm just trying to find a string using the exact string as the regex (escaping 2 times)

cobalt cedar
#

Can someone suggest a source to learn django like video tutorials?

dapper tusk
#

Corey Shafer has a nice series

lethal orbit
#

With apollo client on the front-end side.

cobalt cedar
#

Corey Shafer has a nice series
@dapper tusk thanks mahn

native tide
#

thanks

sly canyon
#

Anyone with experience implementing Marketing API/Conversions API using Facebook Business SDK for PY?

native tide
#

Hi guys

#

I'd like to pass in a Jinja2 expression into a WTForms input placeholder.

WTForms input:

{{ form.email(class="formfield", disabled=True) }}```

I want it to have a placeholder="{{email}}". I can't find how to do this. Does anybody know what to do here?
#

I've found a workaround by just replacing it with a div that has the exact same look as a formfield, but still, I'd love to know how to do this.

native tide
#

@native tide you wanna a placeholder name ="Email"?

cold socket
#

Hey all I have this query in Flask to retrieve data from my database using the id key. @app.route('/api/store/<id>', methods=['GET']) def get_store(id): store = Store.query.get(id) return store_schema.jsonify(store) How can I query it with another parameter instead of id such as a unique string

#

I have 3 columns: id, name, date.

native tide
#

@native tide I want the placeholder to be a jinja2 variable {{email}} which I pass from the flask route

cold socket
#

I want to query it using name which is unique

native tide
#

@cold socket You can do Store.query.filter_by(name=name) etc

cold socket
#

@native tide Now that I think about it. Does name have to be a primary key?

native tide
#

primary key only can be true

#

oh id name?

#

no, your ID should be the primary key.

say you had a user in your database with ID 1, and name 'Jeff'

You can do database.query.filter_by(name='Jeff') and you'll get his object

#

id shoule be primary key

#

it's required

#

then you can manipulate the object to get the info you need

cold socket
#

Ah okay that makes sense. Thank you so much!

native tide
#

No problem! 🙂

#

No problem

native tide
#

Hi guys, I keep trying to use Flask-Migrate for DB changes, but everytime I'm getting this error. I've fully deleted the migrations folder and this is the error:

INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
ERROR [root] Error: Can't locate revision identified by '28d844d650b0'

the sequence of cmd commands:

flask db init
flask db migrate -m "Initial migration."
flask db upgrade

Has anyone had the same issue?

fierce hare
#

Hello all. Today I stumbled upon this https://github.com/robinhood/faust and was wondering if someone could maybe explain a real world example maybe of how this is useful? I read it multiple times and tried to find projects that use this with flask or sanic (which is what I'm using) but failed to do so.

#

How would this be added to sanic (I use sanic to build a REST API for an note taking app that I'm making) and how would it benefit me?

noble star
#

How does a person make tests for web aplications like flask?

#

Or web stuff in general?

valid orbit
#

Hey @noble star, That's a pretty broad question. Can you narrow it down at all?

#

Most web frameworks offer support for testing as part of the framework.

agile ermine
valid orbit
#

For example, in Flask you have access to a test client as an attribute of your flask app. app.test_client() gives you this object. You can use it sort of like a web browser to make get/post/put/delete requests

agile ermine
#

Postman can also be used to test responses from an api

valid orbit
#

yep.

#

Tests that send a request to some endpoint in your web application are a great place to start.

#

You can test that the expected urls exist, and that the right kinds of HTTP methods are available (and unavailable)

agile ermine
#

Yis. And expect whatever status code and the output for the response as well. And also see the response time

valid orbit
#

You can test logging in and out, and whether a user has to be authenticated to access a particular endpoint too

#

If you want to go beyond that, most web applications have lots of classes and functions in them as well. And in most cases those can and should be unit tested.

noble star
#

Cool Thanks @valid orbit that is what I needed

sly canyon
#

Hi guys, I have the following environment variables set on .env / .flaskenv meant to use it when I run my web app on localhost

TESTING=True
FLASK_ENV=development

But, I'd like to set

TESTING=False
FLASK_ENV=production

Whenever I commit and deploy changes through git push heroku deploy:master. Meaning that if it's not running local, it would change those variables.
Having to manually change those variables everytime I commit leaves room for an additional human vulnerability (which is me forgetting to change those, which would enable a blueprint with test routes that I wouldn't like to be deployed nor allow those endpoints to be scraped and displayed on SERPs)

versed python
#

you can use environment variables and set them on your heroku server Accordingly. You can also use pre/post commit git hooks. I suggest you try the first one.

sly canyon
#

@versed python I do commit and deploy my .envand .flaskenv files to Heroku and load them using dotenv.load_dotenv when I initialize my app using config.py. That's exactly the issue here, I want to force those changes in case I forget to change these environment variables when I'm testing stuff locally.
P.S: Will read about git hooks, never heard of that.

agile ermine
#

You shouldn’t have to commit the .env files to Heroku

versed python
#

I think you should use environment variables instead of .env files. That way you can have different values for different environments. then you can do something like SECRET_KEY = os.environ.get('SECRET_KEY').

agile ermine
#

If you go on the app’s settings in Heroku, there are environment variables you can easily set. It will work the same way with load dotenv

versed python
#

You shouldn’t have to commit the .env files to Heroku
@agile ermine yep, .env files are supposed to be developer specific. Infact if you look into the default .gitignore file that github provides, you will see .env would be included there.

agile ermine
#

So locally, keep the .env file. But don’t push it to github. You can just adjust the environment variables on Heroku and it will work the same way

#

Exactly! Especially if you make your repo public too

sly canyon
#

I think you should use environment variables instead of .env files. That way you can have different values for different environments. then you can do something like SECRET_KEY = os.environ.get('SECRET_KEY').
@versed python Yes, I think I have this going on here on my config.py file

worn rapids
#

^ agree

sly canyon
#

If you go on the app’s settings in Heroku, there are environment variables you can easily set. It will work the same way with load dotenv
@agile ermine Will try

versed python
#

If you go on the app’s settings in Heroku, there are environment variables you can easily set. It will work the same way with load dotenv
@agile ermine yep this is the correct way

sly canyon
#

I am sure that I have added .envand .flaskenv to gitignore, but I've stopped to deploying my app to github and I'm commiting changes directly to heroku, not sure if Heroku looks for a different .gitignore file now that you have mentioned it.

#

Oh, shoot, seems like I have not added .envand .flaskenv files to .gitignore, I'm just checking it right now. I may have deleted it last time I have deployed it to github

versed python
#

Heroku works using the basics of git, so it follows all rules of standard git. So yeah, it looks for .gitignore too.

sly canyon
#

Yes, I'm sure now that I'm commiting those files after seeing the variables

#

Seems like I have to create a whole lot of variables there

agile ermine
#

Yes, you would just set those variables there but shouldn’t commit your .env file as that might contain sensitive data

sly canyon
#

Indeed, all my integration keys, tokens, etc. are stored there

#

Thank you guys @agile ermine @versed python @worn rapids , I think I've everything sorted out now. Tomorrow I will deploy to test if everything is working properly

agile ermine
#

👍 happy to help!

worn rapids
#

i didn't do anything haha, but excited for u!

past cipher
#
def fetchAllProductStock(self, productID):
    return self.query.filter_by(productID=productID).all()

inside this table is a row called item, how can I do something like:

def fetchAllProductStock(self, productID):
        return self.query.filter_by(productID=productID).all().productName

I want to first all items productNames inside this query

#

This will work:

def fetchAllProductStock(self, productID):
        query self.query.filter_by(productID=productID).all()
        names = []
        for item in query:
            names.append(item.productName)
        return names

But it seems long. Surely there must be a way to do it in one line with sqlalchemy ?

vestal hound
#
def fetchAllProductStock(self, productID):
    return self.query.filter_by(productID=productID).all()

inside this table is a row called item, how can I do something like:

def fetchAllProductStock(self, productID):
        return self.query.filter_by(productID=productID).all().productName

I want to first all items productNames inside this query
@past cipher [item.productName for item in self.query.filter_by(productID=productID).all()]

#

incidentally, in Python you should use snake_case instead of camelCase

past cipher
#

yeah I always forgot to use snake case, a couple of people have mentioned this to me, when i'm quickly writing code I mix them up and end up eventually fix it

#

will try your above code now

#

works great @vestal hound , thanks!

vestal hound
#

np

#

works great @vestal hound , thanks!
@past cipher actually I think you might want to remove the .all()

#

it should stll work

past cipher
#

yep you're right, no need for all()

vestal hound
#

yep you're right, no need for all()
@past cipher there's a difference

#

.all() turns it into a list

#

so there's an extra list created (less efficient)

past cipher
#

seems to turn it into a list regardless

vestal hound
#

no

#

.all() makes a list, then the list comprehension makes another list from it

#

whereas the Query object is an iterator (doesn't produce values until necessary)

#

so only one list is ever created

#

(the result)

frozen python
#

I created a project name “SHOP” and my first app is “PRODUCTS”,

My files go:
*Shop
-products
-shop
-venv

Is that right? I’m using VSC

#

“Products” is my first app.

paper axle
#

what

paper axle
#

k

frozen python
#

Should pages, be it’s own App in Django?

#

Or is just adding them to a templates folder good enough?

versed python
#

different parts of your website should be different apps. For example, you'll probably want to separate user handling into a separate app called accounts and blog posts into a separate app called posts. So to answer your questionsl, no, each page will generally not be its own app.

west jay
#

Hello! i'm interested to learn django, and crossed these two tutorials
https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django
and
https://docs.djangoproject.com/en/3.1/intro/tutorial01/
Which one is better to take?

versed python
#

The second one. Actaully both are good but its generally more preferable to learn a framework from its offiial docs @west jay

#

So yeah go with the second one

west jay
#

thanks!

wraith prawn
#

hey guys - completely new to django (fairly new to python).... anyone able to help with getting a chart to display when i runserver? it shows when i run locally pasting the path into chrome

#

ive found a few different things on google but couldnt resolve (using window.onload =function ete, also found about some google security issue, but couldnt figure that bit out)

versed python
#

what kind of a chart do you want? @wraith prawn

wraith prawn
#

line / bar charts

#

from what ive just read its to do with having the location hardcoded ? im watchign some vids now to try understand it a bit more

versed python
#

Do you know how to use some kind of graphing library (eg Matplotlib or Plotly)?

lethal orbit
#

I would recomment something client-side like Chart.js and passing the data as JSON.

versed python
#

I had a lot of success with plotly too, especially if you want to make the graphs using python

lethal orbit
#

Not familiar with Plotly, but matplotlib's API is... special lol

#

Great project, but hard to configure.

versed python
#

yep

wraith prawn
#

@lethal orbit so I tried using chart.js, I have a separate JS file that has my charts in it with the data. should that instead be passed directly into the HTML ? (ill also look this up, not after someone doing all the work for me ! )

lethal orbit
#

Mostly depends on your project structure. I usually use Quasar/Vue.js as a client, and have a Django REST or GraphQL API.

versed python
#

wait you use vuejs?

lethal orbit
#

I think a JS file would be fine.

#

Me, yes. Vue.js is love.

versed python
#

Oh god. How do you get it to run? I am having so many issues... Can you tell me where you learned how to integrate django and Vue together?

lethal orbit
#

Easiest/best way I find is docker-compose, nginx, one node image for Vue, one python image for Django, and ariadne for GraphQL (back-end) and apollo-client on the front-end.

versed python
#

Isin't Vuejs supposed to be the front-end?

#

I already use docker-compose to run a python container, a nodejs and a third one for postgresql @lethal orbit

lethal orbit
#

Yup, its front-end.

#

if you want, we are working on an open-source project using Docker-compose, Django, Quasar, Vue, Postgres... you can always join, and look at the code.

#

So you can see the code without joining.

versed python
#

docker-compose -f docker-compose.yml -f docker-compose.dev.yml up Why exactly did you use two different docker-compose files here?

#

But yeah I will try it out, thanks @lethal orbit

lethal orbit
#

NP. If you want to join us in working on it, feel free (though we're kind of busy with pyweek this month) to DM or ping me.

#

We have a fair bit of experience and you can definitely learn something.

#

docker-compose -f docker-compose.yml -f docker-compose.dev.yml up Why exactly did you use two different docker-compose files here?
@versed python Maybe not the best / most DRY approach, but I usually split those up into different environments that have different needs.

#

This one only has a dev stage for now, but it's a nice way to then set up a staging environment, and a production one, etc.

versed python
#

well, I will be looking into the progress every now and then. I am too inexperienced to contribute though.

lethal orbit
#

Nonsense 😄

#

How do you get experience if not by working on projects?

high herald
#

So uh, I got a pretty weird email and I don't know how to best respond to it

#

I sell collectible trading cards online, and a customer randomly registered a whole bunch of shady sounding URLs related to the product and wants to "help" us by redirecting them all to my store until he figures out what he wants to do with it.

#

Is this something I can prevent? This guy sounds like a massive headache based on the rest of the email and I don't know enough about SEO etc to even begin to guess if this is even an issue for me.

rancid lintel
#

Is there a simple way to show a modal in combination with a specific route?

-> show posts list

/post

-> show modal (on top of the posts list)

/post/:id

native tide
#

@high herald Probably a scam. Block them.

#

No point in wasting your time for an "If"

high herald
#

What do you mean by block them?

#

Is that a thing I can do? If a random person wants to do a 301 redirect from some random site they purchased to mine, is that something I can block? Or are you referring to just blocking their email so that I don't get more of these messages

#

@native tide

native tide
#

Block their email

#

If you think something is suspicious enough that you had to ask other people, i think its safe to assume its too suspicious. If you get an email from a stranger giving you a good deal, whose email has a link, avoid them.

high herald
#

Unfortunately, I don't think this is a scam. I sell trading cards for a popular card game and this is a regular customer.

#

and customers -constantly- decide they want to start a youtube channel, do a podcast and pull similar things like this all the time

native tide
#

hmmph

high herald
#

That being said, I've never had a customer just decide they want to buy a bunch of urls and 301 them to my website

native tide
#

how long have you been doing this?

high herald
#

It costs them money and as far as I understand, it does nothing.

#

I don't know, 16 years? I couldn't even tell you when I started

native tide
#

okay then if this is the first time you got such a request in more or less 15 years

high herald
#

This is really straying off course of the question I was intending to ask

#

If we can just abstract away my situation for a moment

#

What prevents me from registering www."somethingreallyoffensive".com and redirecting it to apple.com or something

#

and if that even matters if some random stranger does this

native tide
versed python
#

Don't quote me on this, but I think django can detect which host is requesting its website (hence the ALLOWED_HOSTS setting in settings.py). Maybe you can use that to redirect users?

#

@high herald

jagged lark
#

Yes, it is a request header, Host

versed python
#

I think i am majorly incorrect though

jagged lark
#

Nah, you're right actually

high herald
#

Ah, that's helpful. Thank you

prisma jackal
#

I created question and answer website using django I stuck on How I can associate each question or answer to a given comment in django models together with votes.

versed python
#

Link it here so that someone can help you

#

Ah, that's helpful. Thank you
@high herald even if I am, i dont see how that's gonna help your particular use case?

high herald
#

Perhaps I misunderstood what you were trying to communicate with me. It at least gives me a reasonable thread to start my own research

#

I was under the impression that there would be an option somewhere so that I could prevent a redirect, somewhat analogous to sites that disable hotlinking. But given your follow up, I guess this is not the case.

prisma jackal
#

How can i implement vote, comment section reletes to a question and answer in django models?

lethal orbit
#

How can i implement vote, comment section reletes to a question and answer in django models?
@prisma jackal Add a vote model with a UniqueConstraint on user, question, with a foreign key to question

#

and a Comment model with a foreign key.

prisma jackal
#

What is uniqueConstraint @lethal orbit

versed python
#

I feel like you're a beginner. Have you completed any django tutorials? @prisma jackal

prisma jackal
#

@versed python yes

#

I just started, this is my third project

lethal orbit
#

Google django UniqueConstraint 🙂

#

Probably quicker than waiting for me to be not busy; sorry.

weary dragon
#

some good guides for unit testing and migrations in flask?

native tide
#

Flask SQLAlchemy;

If I set a relationship between a 'User' class and a 'Review' class, can I access the Review class through the User class?

prisma jackal
#

@lethal orbit I don't see very friendly article to me here.

native tide
#
user.profileam
[<ProfileDB 1>]
user.profileam.name
Traceback (most recent call last):
  File "<input>", line 1, in <module>
AttributeError: 'InstrumentedList' object has no attribute 'name'```

'user' is a DB row of 'User'. It has a relationship to another DB through the variable 'profileam'.

By doing user.profileam, it shows a row in the other DB. But it's a list, and I can't access any data in the other DB such as name.

Am I understanding this right? How could I fix it?
lethal orbit
#

You just need to add a UniqueConstraint in class Meta

#

Function Definition in Python by Sadrach Pierre, Ph.D. in TData Science [spam url removed]
@native tide what does this have to do with web dev?

#

Why just spam nonsense no one asked about?

prisma jackal
#

@lethal orbit yes! Thank u, I got nice article. Thnk u so much

native tide
#

@native tide what does this have to do with web dev?
@lethal orbit
I accidentally sent it here😅

#

@lethal orbit I left it here for someone to possibly take advantage of in data science & web dev

lethal orbit
#

@lethal orbit I left it here for someone to possibly take advantage of in data science & web dev
@native tide so, spam. Got it.

#

Congrats, you're the first person on my block list 🙂

native tide
#

Thank you 😂

lucid vine
#

Is it possible to make async requests with requests library? And if not what is the best library for them

lethal orbit
#

Is it possible to make async requests with requests library? And if not what is the best library for them
Haven't used it, but have heard good things about httpx: https://www.python-httpx.org/

#

I need to get in on that async train.

limber laurel
lucid vine
#

@lethal orbit yeah I am currently making an API and I gotta make multiple requests somewhere to return a result and without async it is taking too long to be acceptable. Will try httpx, just gotta wrap my head around this as well https://docs.authlib.org/en/latest/client/httpx.html

lethal orbit
#

Could anyone help me understand, how does this work?
@limber laurel poorly xD

#

It creates a WebSocket with a string concatenation.

#
const chatSocket = new WebSocket(`ws://${window.location.host}/ws/chat/${roomName}/`);
native tide
#

btw if you guys are trying to use logic like ==True in jinja2 templates the logic must be lowercase, e.g. true

quiet lily
limber laurel
#

@lethal orbit Alroght thank you

native tide
#

Why in Javascript we should avoid declaring Number & String & Boolean with the word new?

fast basin
#

In Django website static files like css, images and sounds works on my localhost but they are not working on my aws windows server?

lethal orbit
#

In Django website static files like css, images and sounds works on my localhost but they are not working on my aws windows server?
@fast basin do you run python manage.py collectstatic and serve them properly? Django only serves static files if DEBUG is True

#

It's not meant to be used in production.

past cipher
#

Can someone explain to me the advantage of using websocket? I have this Javascript which works fine:

function runStripePayment(productID, stock){
            document.getElementById('product-popup-' + productID).style.display = 'block';
            
            if(stock === '0'){
                return false;
            }
            
            var response = fetch('/create/' + productID + '/secret').then(function(response) {
                return response.json();
            }).then(function(responseJson) {
                var clientSecret = responseJson.client_secret;
                var form = document.getElementById('payment-form');
    
                form.addEventListener('submit', function(ev) {
                ev.preventDefault();
    
                stripe.confirmCardPayment(clientSecret, {
                    payment_method: {
                    card: card,
                    },
                }).then(function(result) {
                    if (result.error) {
                    console.log(result.error.message);
                    document.getElementById('stripe-error').style.display = 'block';
                    document.getElementById('stripe-specific-error').innerHTML = result.error.message;
                    } else {
                    if (result.paymentIntent.status === 'succeeded') {
                        document.getElementById('s-token').value = clientSecret;
                        document.getElementById('user-delivery-email').value = document.getElementById('delivery-email').value;
                        document.getElementById('form-productID').value = productID;
                        document.getElementById('purchase-check').submit();
                    }
                    }
            });
            });
            });
        }

However, I was told I should really be using websockets, as this JS code could be manipulated by a malicious user. I just don't understand how a web socket would work

#

considering the websocket would should the full paymentIntent data

native tide
#

hi does anyone here know js?

#
<script type="text/javascript" 
 
src="code.js"></script>```
#

can someone help me with what this code means

past cipher
#

its a script tag linking to code.js file

native tide
#

so basically what happens if u type it in smthn like vsc? @past cipher

past cipher
#

vsc ?

native tide
#

yea

past cipher
#

what is that

native tide
#

like what is the output?

#

visual studio code

#

its a code editor

past cipher
#

i know, i don't understand your question

native tide
#

what happens when u run that script

past cipher
#

it will import code.js file in your html document

native tide
#

ohhhh

#

so if u have a file name code.js

#

you can import it to ur html file using that code?

#

@past cipher

past cipher
#

yes

native tide
#

ight thx

#

nice pfp btw

past cipher
#

lol you're not the first to say that

native tide
#

lmao

past cipher
#

I literally just googled "avatar"

native tide
#

lMAO

#

ight imma go to solo learn peace out

past cipher
#

✌️

maiden kraken
#

so.... what's the best way to store a LIST inside django model? Is it even possible to have a list in sqlite database in one cell?

past cipher
#

how big is the list

maiden kraken
#

4 elements inside, each element is a datetime

past cipher
#

if using db, could use relational tables

#

not sure about django, not used it

maiden kraken
#

shit sounds complcicated 😛 I will try to google thi phrase thanks a lot

past cipher
#

nah pretty easy once you understand it

#

20 min youtube video and you'll probs understand

hallow jacinth
#

anyone good with heroku apps? I am having db trouble xd

past cipher
#

@maiden kraken

#

not sure if its best option for your needs, but always useful to know when dealing with db

versed python
#

anyone good with heroku apps? I am having db trouble xd
@hallow jacinth yeah?

maiden kraken
#

@past cipher thanks a lot man, really appreciated your help and spending time to help beginners!

hallow jacinth
versed python
#

guys I need a help in js. What does const { data, id } = payload mean? I mean what does that syntax do?

dapper tusk
#

@versed python it means that payload is an object with keys data, id (and maybe more), and those 2 keys get set to variables of the same name

versed python
#

SO it is extracting it basically?

dapper tusk
#

Yeah, pretty much

versed python
#

is this vanilla js or is it something like idk es6? @dapper tusk

dapper tusk
#

ES6 is vanilla JS

#

It is probably an ES6 feature

vague ibex
#

Vanilla JS is just normal JS. That's it.

#

No need to worry about it lol

versed python
#

So that is normal javascript? const { data, id } = payload

vague ibex
#

I've seen people struggling to understand what is vanilla JS. To make the long definition short, Vanilla JS = normal javascript

#

yeah

dapper tusk
#

Yep

versed python
#

since i have never seen it in my own js basics courses anywhere

dapper tusk
#

You can do it in a browser console

vague ibex
#

Actually, the name was given to it simply to prove that Javascript is a powerful language even without any plugins

versed python
#

oh yeah, ik it works. I just wasn't sure how

#

doesn't Vanilla mean default? @vague ibex

vague ibex
#

yeah normal javascript is default

#

as it does not include any plugins initially

dapper tusk
#

Since ES6, JS is actually useable without external libraries, though they still help

vague ibex
#

^

versed python
#

so for example there is a module called axios. Is that a plugin? or vanilla?

vague ibex
#

Since ES6, JS is actually useable without external libraries, though they still help
@dapper tusk JS is actually believed to be pretty powerful. The name "Vanilla" is just used to make it look cool xD

#

so for example there is a module called axios. Is that a plugin? or vanilla?
@versed python There's a difference between module and plugins

#

What is "Vanilla JavaScript"? ... "VanillaJS is a name to refer to using plain JavaScript without any additional libraries like jQuery. People use it as a joke to remind other developers that many things can be done nowadays without the need for additional JavaScript libraries."

#

^ for clearing ur doubt regarding vanilla js

#

its a source from google

versed python
#

that makes sense

dapper tusk
#

Vanilla is a common term for things with no extensions

vague ibex
#

vanilla ice cream kek

versed python
#

Vanilla is a common term for things with extensions
@dapper tusk this confused me again

versed python
#

Vanilla js is batteries included or not?

vague ibex
#

You'll understnad

dapper tusk
#

Oops, no extensions, typod

vague ibex
#

lol lakmatiol

dapper tusk
#

I am terrible at not skipping words when on a phone, sorry

versed python
#

just use text to speech duhh

dapper tusk
#

That would wake the dog up

versed python
#

(actually please don't it's horrible)

vague ibex
#

IgnisDa, did u get ur doubt cleared?

#

If not, tell me

versed python
#

yeah I did pretty much.

vague ibex
#

Its nothing to worry about lol

#

Vanilla JS is just plain js

versed python
#

but I still dk why you said plugins and extensions are different

vague ibex
#

o,o

#

i dint say that

#

A plugin is, like its name says, a piece of software that you can plug into an application to provide new functionality. Plugins usually implement well defined API's and are reactive (that is, they provide services that the main application can use).

#

This is what stackoverflow says

versed python
#

oh

vague ibex
#

You can refer to the link I sent earlier

#

This gives a clear explanation in smooth words

versed python
#

and this "component" referred to here. Is that different from Vuejs components?

vague ibex
#

be it java or javascript, plugins and modules are terms in general

#

and this "component" referred to here. Is that different from Vuejs components?
@versed python What do you mean by Vuejs components?

#

A component is any piece of software designed to be reusable.

versed python
#

Oh it is a js framework

vague ibex
#

so, component is just like a software

#

lol

#

yea, ik its a framework

#

A framework may/may not be a software

versed python
#

A component is any piece of software designed to be reusable.
@vague ibex Yeah thats what Vuejs decribe componenets in the docs too

#

so django and vuejs are frameworks right?

vague ibex
#

yep

versed python
#

thank you

#

LEGEND

vague ibex
#

No worries ^_^

#

My objective is to help people clear their doubts lol

versed python
#

how does one get so much knowledge from though?

vague ibex
#

Whenever I have a doubt of my own, I just try my best to get a solution from it

versed python
#

how long have you been doing this stuff?

vague ibex
#

how does one get so much knowledge from though?
@versed python Its like what u acquire

#

Well, I'm 14 (turning 15 this year)

#

how long have you been doing this stuff?
@versed python I've started programming casually at 11

versed python
#

that's cool, I am 18

vague ibex
#

I'm more inclined towards web development

versed python
#

what I meant was, how long have you been dabbling in web development and stuff?

vague ibex
#

so its like 14-11 , that gives 3

versed python
#

and what languages do you know other than python and js?

#

does one need to know anymore for web development?

vague ibex
#

Yea

#

Web development is a constantly evolving tech ngl

versed python
#

other than HTML CSS

vague ibex
#

Its like you know JS today, and a new cool language comes up tmrw

#

you need to keep pace with the tech

#

if u dont, you get beaten in the race by other web devs

#

It actually depends on the work ur gonna do

#

Learning more is always better

#

But you need to learn the things carefully and clearly

#

there is a wide range of frameworks

versed python
#

what exactly do you mean by learning more? Learn more languages? Frameworks?

vague ibex
#
  • langugaes
#

both languages and frameworkjs

#

frameworks*

#

and tips and tricks, you know

versed python
#

whooo I have a lot to learn lol

vague ibex
#

It is better to have a good grasp on the cool techs

#

suppose your client tells u to make an E-commerce site, you can have an idea of what to use and what to not

#

I can make a simple website out of html, css and js for e commerce purposy

#

purpose*

#

But if i want it to be a legendary website(Exaggerating ) , then i would prefer django, react and such things

versed python
#

but its probably easier to do with Vuejs or something?

vague ibex
#

There r plenty of technologies in the market

#

anything can be done to make an e commerce website

#

your sense/idea is what it requires

versed python
#

I heard react is much more difficult than Vue. Thats why i got started with vue

vague ibex
#

if u have already learnt the techs, it will be easy to make a plan

#

IgnisDa, do you know js or python?

versed python
#

alright anyways thanks for helping me out. Much appreciated! I gtg now

#

if u have already learnt the techs, it will be easy to make a plan
@vague ibex both

vague ibex
#

ah thanks! cya! o/

versed python
#

i mean ik both py and js

vague ibex
#

happy coding! 😄

versed python
#

thanks and same to you

vague ibex
#

then it would be easier for u to move on to frameworks

#

yea cya o/

regal furnace
#

Good day! I want to learn how to write tests. So can anyone suggest good tutorial or something like it how to write tests for django apps? Except official docs

vague ibex
#

you mean like a quiz app?

weary dragon
#

i think he want a tutorial to make unit test for his app

#

i want one too but i am using flask

regal furnace
#

In my case it's django blog app

native tide
#

Hi. First of all, very sorry for the probably stupid question. I am very new to coding python.

I have created a machine learning model using python which uses a simple text input string to generate some output.

I am running this using Colab, but also locally.

I now want to deploy this project to a website using a simple HTML field and a submit button. Once the user enters some text, i want to pass this string to my external python (.py) file

Normally I do this with python using e.g. "python input.py --input "Some string".

I've been looking a little at FLASK, but i don't seem to find any good pointers on how to work with separate python files, rather than passing around arguments inline.

Any help would be appreciated, where I should start looking. Again, I am a total noob when it comes to this

maiden kraken
#

@regal furnace There is a book about test driven development in django by Harry Percival

#

I won't tell you if it is any good tho, that topic is unknown to me

regal furnace
#

@weary dragon I want to learn how to use Django simple test case as example

vague ibex
#

Hi. First of all, very sorry for the probably stupid question. I am very new to coding python.

I have created a machine learning model using python which uses a simple text input string to generate some output.

I am running this using Colab, but also locally.

I now want to deploy this project to a website using a simple HTML field and a submit button. Once the user enters some text, i want to pass this string to my external python (.py) file

Normally I do this with python using e.g. "python input.py --input "Some string".

I've been looking a little at FLASK, but i don't seem to find any good pointers on how to work with separate python files, rather than passing around arguments inline.

Any help would be appreciated, where I should start looking. Again, I am a total noob when it comes to this
@native tide When a Button is clicked, you can call a function using command option. Assign the command option with the function name you would like to call when the button is clicked.

regal furnace
#

Thank you @maiden kraken👍 I'll try to find this book, maybe it will be useful for me!

native tide
#

@vague ibex and i can pass what ever string is in the input field to a python file?

vague ibex
#

Thank you @maiden kraken👍 I'll try to find this book, maybe it will be useful for me!
@regal furnace If you don't like books, I'd prefer youtube videos lol

#

@vague ibex and i can pass what ever string is in the input field to a python file?
@native tide Most probably, yeah

native tide
#

hehe "most probably"

vague ibex
#

check this out

hallow jacinth
#

anyone with a web app hosted on heroku using flask and postgress db think they could help real quick :o

native tide
#

Thanks a lot. I will sure have a look at it. I have managed to create the web page itself

vague ibex
#

cool! I hope you can manage to do it! Happy Coding!

native tide
#

i will sure try

vague ibex
#

good luck!

native tide
#

Can I also receive an output from that file to show on the webpage btw?

#

so it is kept as a variable

#

session

#

i basically want to use my python file as an API of sorts

#

input > output

vague ibex
#

yea i got you

native tide
#

basic i know

#

🙂

vague ibex
#

so you wanna take the input, apply a function on it and display an output?

native tide
#

yes indeed. Even make a file available for download

#

which is generated by the script

vague ibex
#

yea sounds nice

native tide
#

so lets say i input "cat" into an input field, and the function will return an image of a cat

#

although it is more fun than that 🙂

vague ibex
#

wow thats cool\

native tide
#

lol no

#

actually it will take a text as input, then generate a text to speech sound file

#

using a custom voice

#

that all works already

#

but the web deployment is tricky for me

vague ibex
#

btw lemme show u something rlly cool and interesting

#

presenting DOM manipulation using python!

native tide
#

oh man, its like greek to me

vague ibex
#

Its rlly easy to use and cool

native tide
#

ok, i will have to try to figure it out

regal furnace
#

No meter for me@vague ibex. I'll be glad for any good advice!

vague ibex
#

nice

#

If you want to do web deployment, knowing things regarding DOM proves to be rlly useful

native tide
#

i can imagine

vague ibex
#

:]

native tide
#

im a ux designer, so havent had to do this before 🙂

vague ibex
#

UX design's fun! 😄

#

especially when u can also implement those in a website/webpage

native tide
#

hehe i rarely have to do it myself

#

but this is an own idea

#

not work related

vague ibex
#

anyways i gtg cya!

#

o/

native tide
#

thanks again

native tide
#

if im using flask and i have a csv file i wanted to display

#

should i keep it as a csv file or convert it to SQL

frozen python
#

I’m tutorials with Django.... no one barely talks about “initiated” a class. That’s what’s been wrong with my DB of objects to show

maiden kraken
#

I think startng with csv is okay. You can always switch to sql db later

lapis spear
#

hello umm
how to add form in detailview currently i am displaying the Post model in detailview and what i want is to add a comment feature on the detailview using Comment model now i don't know how to add the comment form on detailview
can anyone help me please 😅

versed python
#

Django DetailView? @lapis spear

lapis spear
#

@versed python yes yes sir

versed python
#

From what I understand from your question, you're trying to get two different forms (since you arr dealing with two different models) into the same view. Now DetailView is a generic view and is meant to deal with only a single form and single model. You'll probably want to rethink your view and convert it to function based. Otherwise you'll have to do a bunch of subclassing and inheritance and modifications to get what you need.

native tide
#

do u need to know html to learn js?

quick cargo
#

no

native tide
#

kk

#

do u use solo learn for js?

#

cause im using it

quick cargo
native tide
#

and its talking about i mean before it was talking about <body> and <head>

versed python
#

what would you even learn in html? It's just a few angular brackets

native tide
#

so whats the use of that?

#

what would you even learn in html? It's just a few angular brackets
@versed python im not gonna lmao

dapper tusk
#

You probably do want to know basic html before js

native tide
#

well its going smoothley for me

versed python
#

yeah thats right though

dapper tusk
#

Most tutorials teach js in that context

native tide
#

its pretty easy for me ngl js

glass sandal
#

Guys isn't there any way to upload a Django website to an Apache server without mod_wsgi? Cause some hosts don't have command line interface

lapis spear
#

@versed python what im trying to do is using post model to display and comment model for form is it possible in detailview?

native tide
#

ight imma code peace

versed python
#

straightforward answer is no. you will have to do a lot of modifications which will probably not be worth all the time.

glass sandal
#

Oh well

versed python
#

@lapis spear

lapis spear
#

@versed python oh yes yes thank you sir

glass sandal
#

So basically it's possible

versed python
#

use a function based view it will be much easier

#

So basically it's possible
@glass sandal it is but i dont see why anyone would want to go through all that trouble

native tide
#

i have a quest

#

this command:

versed python
#

I did it once just for the sake of learning it was useless in an actual project

glass sandal
#

Oh I see ... And like could I get an overview of what you need to do?

lapis spear
#

@versed python sir when should i use cbv and method views? im at lost

versed python
#

hello umm
how to add form in detailview currently i am displaying the Post model in detailview and what i want is to add a comment feature on the detailview using Comment model now i don't know how to add the comment form on detailview
can anyone help me please 😅
@lapis spear they need help with this

native tide
#

<script type ="text/javascript"
src ="Code.js"></ script >

#

so what this code is doing so if u have two files and one is a html and ur coding in the html and one is called code.js so if u write this script in the html file all of the code from code.js is basically in that script combining with the html code

#

is this write?

#

bascailly bringing a .js file inside a .html file?

versed python
#

why do you call me sir @Hello? please don't. As a general rule i use cbvs since most views are generics. when i need to do something special, i have to switch over to function based ones or write a difficult class based one. depends on the use case.

sharp grotto
#

yep

native tide
#

kk

#

marizuana idk if my discord is lagging but do u have a discord pfp? @sharp grotto

#

or not

#

idk if im lagging

sharp grotto
#

I don't

native tide
#

kk

#

thx

sharp grotto
#

xD

lapis spear
#

@versed python oh nice nice thank you mate 😅 👍

native tide
#

everytime u run a js code after the ()'s do u have to add a ;

#

just like:

versed python
#

glad to help @lapis spear

native tide
#
document.write("Hello World"); //do u have to add the ; in it? ```
versed python
#

everytime u run a js code after the ()'s do u have to add a ;
@native tide its not required but recommended

native tide
#

ok thx

versed python
#

most IDEs will add one by default when they format your code

native tide
#

okay

versed python
#

yeah np

native tide
#

ngl js is easier than python in my opinion

#

i quit python cause its too hard ):

#

and js is perfect

#

but imma learn py after i finish learning js

versed python
#

it's the other way round for me. I find js hard.

native tide
glass sandal
#

Python is eaaaasier than JS

native tide
#

i think js is lmao

glass sandal
#

SO much easier

versed python
#

especially all that Promise and api stuff

native tide
#

js is easier

#

i just started js today

#

and i started python a month ago

glass sandal
#

JS is easy in the first glance

native tide
#

and i dont understand while loops lmao

#

so now im learning js

versed python
#

any language vs language debate is pretty much useless and never gonna be resolved. It's just a developers personal preferences

glass sandal
#

Well the more programming languages you know , the easier it gets to learn new ones

native tide
#

yea

versed python
#

laughs in C++

glass sandal
#

XD

native tide
#

<script>
var price = 55.55;
document.write(price);
</script>

#

is it optional to add <script> ?

versed python
#

you want difficult, get down on the C bois

glass sandal
#

Yesss

versed python
#

nope

glass sandal
#

C hard

native tide
#

u have to add <script>

glass sandal
#

But

native tide
#

<script>
var price = 55.55;
document.write(price);
</script>

#

is it alright if i just added:

glass sandal
#

Let's see what you do with brainfuck

native tide
#

var price = 55.55;
document.write(price);

#

is it the same?

#

Let's see what you do with brainfuck
@glass sandal lmao

glass sandal
#

@native tide Is that in your .js file or your .html?

versed python
#

C hard
@glass sandal The problem with it is you have to learn stuff like pointers ajd memory addresses as part of the basics. Thats what makes it hard.

native tide
#

none

#

im on solo learn

#

lmao

glass sandal
#

@versed python I know C++ , but C is just barebones you know

native tide
#

its talking about data types and was giving an example

#

@glass sandal

#

its js

dapper tusk
#

C is nice for simple programs

versed python
#

Let's see what you do with brainfuck
@glass sandal i saw the Wikipedia page once. Needless to say, i didn't venture anymore lol

glass sandal
#

@native tide You don't need <script> in .js files

native tide
#

kk

#

thx

glass sandal
#

@versed python XDDDD Same

versed python
#

I know C++ too. But i have never really used it for anything major

glass sandal
#

Or like the Cow/Moo language

#

Me neither

versed python
#

just those small calculator programs they make at school

glass sandal
#

Yeah never used it for my real projects , just done some simple algorithm stuff + Some ncurses

versed python
#

python on the other hand is mmmmmmmmmmmm

glass sandal
#

Python is the best imo

#

Not by the syntax

native tide
#

how do u make a new line in js

#

is it also /n?

glass sandal
#

@native tide \n

native tide
#

\n

quick cargo
#

<br>

native tide
#

even for js?

versed python
#

especially coming from C++, i picked up the syntax with a day and made my own hangman with another day

glass sandal
#

Yes

native tide
#

kk

glass sandal
#

For almost any language it's like that

quick cargo
#

\n isnt used in HTML directly

#

unless its specifically markdown

native tide
#

what are the headings u can use in js

#

<h1> i only know that one

#

any more or em?

glass sandal
#

@versed python omg my first lang was C++ and then Python , wow similarities

#

@native tide You need to document.write them

versed python
#

you Indian? @glass sandal

glass sandal
#

Nope

#

Iranian

versed python
#

hmm

native tide
#

im muslim

#

i live in canada born in england my parents are from pakistan

versed python
#

i was taught C++ at school, learnt py myself. wbu?

glass sandal
#

I'm not too much into religious stuff , tho I respect them

#

@versed python Learned all by myself

native tide
#

i learned myself too

#

im not like perfect in coding

#

like im still learning js and py

glass sandal
#

I'm just like 14 tho

versed python
#

I don't think anyone from our generation is really serious about religion

native tide
#

but stopped py yesterdau

#

im 13

glass sandal
#

Good

versed python
#

im 18

native tide
#

lmao

glass sandal
#

Woah

#

XD

versed python
#

yep

native tide
#

i like to code cause i wanna make a buisness

#

i can photoshop so i wanna make a buisness where i create ads

#

i can video edit too

versed python
#

you should start by learning how to spell business my man @native tide

glass sandal
#

No I loved coding in the first place , cause I LOVED inventing . And inventing needs money . Coding is like inventing from scratch . That's what I loved about it

native tide
#

lmao

#

business

#

isnt it buisness ?

#

wait it isnt

glass sandal
#

business

native tide
#

lmao i thought it was that for my whole life

glass sandal
#

Don't get spell problems please lol

native tide
#

kk

#

i wont

versed python
#

I love coding since people are annoying. mostly.

native tide
#

lmao

glass sandal
#

Lol?

native tide
#

i have a quest about hacking its a pretty weird quest but was wondering

versed python
#

nah you guys are fine. people are fine when you vibe with them

glass sandal
#

lakmatiol is

#

gonna

#

tell

#

us

#

to

versed python
#

otherwise m.. mehh

native tide
#

is there a hacking lang ?

dapper tusk
#

I like coding because it is really hard to make an irreversible mistake

glass sandal
#

goto

dapper tusk
#

Though this is getting ot

glass sandal
#

@native tide Python is the best I could think of?

native tide
#

oh

#

is there a way to make ur own coding language using a coding language

versed python
glass sandal
#

Yes

native tide
#

like using js to make a coding lang

glass sandal
#

YEsss

lapis spear
#

@versed python yo😅 how can i reference in view the currently displayed data in my detailview?

#

like accessing the post title in detailview

#

i want to fill the user and post field by current user and displayed post in detail view in my comment model is this the right solution?
def form_valid(self, form):
form.instance.user = self.request.user
form.instance.post = self.request.post.id
form.save()

#

this is the comment model

#

class Comment(models.Model):
post = models.ForeignKey(Post, related_name='comments', on_delete=models.CASCADE)
comment = models.TextField()
user = models.ForeignKey(User, on_delete=models.CASCADE)

#

@versed python

versed python
#
instance = form.save(commit=False)
instance.user = self.request.user 
#... whatever else you want... 
instance.save()
#

@lapis spear

lapis spear
#

@versed python i got an error it seems a field in comment is not filled after sent
NOT NULL constraint failed: blog_app_comment.post_id

versed python
#

well yeah you have to associate a post id to it.

#

wait what

#

no

#

instance.post = form.cleaned_data.get('post') use this @lapis spear much easier

lapis spear
#

@versed python alright thank you 😅

versed python
#

WHO DO YOU THINK YOU ARE CALLING SIR?

#

Seriously tho please don't

lapis spear
#

@versed python oh i edited it sorry😅

#

@versed python yo this must be a silly question it seems like i don't understand much what im doing but i think its solving the problem does that count? can i proceed and just hope the as time goes i will understand it?

#

or should i take a rest and understand it?

versed python
#

yep that's how i do stuff. just follow blindly whatever the right way is, i end up getting it later

lapis spear
#

for example what the hell does this do?
def post(self, request, *args, **kwargs):
self.object = self.get_object()
form = self.get_form()
if form.is_valid():
return self.form_valid(form)
else:
return self.form_invalid(form)
😅

#

@versed python oh i see nice nice i m hoping that the more i repeat those stuff i will understand it

versed python
#

yeah

#

for example what the hell does this do?
def post(self, request, *args, **kwargs):
self.object = self.get_object()
form = self.get_form()
if form.is_valid():
return self.form_valid(form)
else:
return self.form_invalid(form)
😅
@lapis spear which part?

lapis spear
#

@versed python self.object = self.get_object() this one sir

#

the others i think i get it like getting form and checking if its valid or not

versed python
#

if you look into the source code of this particular CBV, you will find it implements a def get_object method.

#

@versed python self.object = self.get_object() this one sir
@lapis spear this particular line is just calling that method and associating it with the object attribute

#

if you have time, i highly recommend you checkout the django source code. You'll learn a lot, especially since it is well commented.

native tide
#

can someone help me with js increment and decrement

#

i dont get what it does

lapis spear
#

@versed python alright thank you again mate 😅

versed python
#

yeah no issues

frozen python
#

should I have “2” URLS.PY files?????

#

One in my Project and one in my App?

dapper tusk
#

Yes

frozen python
#

Should it be the exact same routing????

prisma jackal
#

Then you include app's urls in project's urls

#

That is a good design in general, will help during extention of project I can say Same for the template, inside the app folder templates/app

frozen python
#

Shouldn’t the pages “for the app” be only in the app urls? Then the main HTML pages is the actual project?

prisma jackal
#

Yes

sly canyon
#

Has anyone here implemented PageView events using Facebook Business SDK?

frozen python
#

@prisma jackal I only have one “views.py” file and that’s in the app, not the main project

native tide
#

can someone help me?

#
var x = 3;
switch (x) {
  case 1:
    document.write(x);
    break;
  case 2:
    document.write(x+2);
    break;
  default:
    document.write(x+5);
}```
#

can someone tell me what this code means pls

quick cargo
#

um

#

in general

frosty lion
#

its kinda like an if statement?

quick cargo
#

fuck all without context

native tide
#

like whats it doing

quick cargo
#

if you mean the switch statement

native tide
#

i dont get the switch statement

#

im learning it in solo learn

quick cargo
#

its just doing what a block of if elifs would be doing

native tide
#

i dont get break default and swift

prisma jackal
#

Switch is more fast than if statement

frosty lion
#

its another way to write conditional statements i guess

native tide
#

so how is the output 8?

frosty lion
#

its basically doing

#
if x = 1:
  write x
elif x = 2:
  write x + 2
else:
  write x + 5
#

so since x = 3

#

the first two dong work

prisma jackal
#

@frozen python project urls is for handling all urls from different apps. Each app should each own urls then urls from a given app is imported in project urla

native tide
#

its js

#

not python

frosty lion
#

so i goes to the default

#

ik

#

but thats the python eqivilent

native tide
#

ohhh so thats what it means

#

what does switch do?

frosty lion
#

its a way to write a bunch of elifs

native tide
#

ohhh

#

how bout break and default?

frosty lion
#

default is basically the else

prisma jackal
#

Prefer switch to if statement when they are both working equally.

frosty lion
#

the switch executes anything that it matches

#

break will exit the switch

prisma jackal
#

Break prevents fallthrough

frozen python
#

@young saddle so I need to update 2 files then? urls and views?

frosty lion
#

is that django?

prisma jackal
#

@frosty lion yes

frozen python
#

Yes

frosty lion
#

okay

frozen python
#

Why????

#

I have one project that I only have one views.py and it’s in my app, not main project

frosty lion
#

u should have a templates folder for ur html

#

i think its called static

#

only apps should have views im quite sure

#

ur folder with settings and stuff doesnt have views?

frozen python
#

@frosty lion no, that’s a picture of it. Why do I need to update 2 view files? Isn’t one good enough?

frosty lion
#

ur templates folder

#

seems kinda wrong

#

unless u changed how django will search for static files

frozen python
#

I have a products folder with detail.html in it, then it’s the other files for the pages

#

“Shop” is my project, then “product” is a app. Is this setup right?

#

@frosty lion

frosty lion
#

products and shops seems to be at the right level

#

ur templates should be app sepecific

#

and should be inside the folder for ur app

frozen python
#

@frosty lion but, that’s not how the default layout is? Should I have the exact same urls for the shop and products?

#

@frosty lion SHOP is the shop is the project (main) then products is a App

native tide
#

Break prevents fallthrough
@prisma jackal wdym?

honest dock
#

Any experienced django user here?

#

If yes, I'm used some very complex UI made in HTML and CSS. Checked how Django forms work and it seems like it's a bit tricky to use already made forms in Django. Should I go with the trouble or just use Angular connected to DRF?

quick cargo
#

You can make your own forms you know and just send a Post request

#

No point using angular just for some forms

honest dock
#

Do you have any guide that shows it? Never done Django beside drf

quick cargo
#

Litterally raw Html and css will work

honest dock
#

Oh okay, and views will do the work?

#

Oh okay, and views will do the work?

#

Oh okay, and views will do the work?

#

Holy crap sorry

quick cargo
#

All you need on django's side is a check to see the request method and get the body if its a Post request

honest dock
#

Great. So forms can be skipped

#

I mean django forms

#

I mean django forms

quick cargo
#

I Litterally never touch any of the form generators

#

Making your own forms are easy enough

honest dock
#

Cool, mind if I add you to show if it's done right when i get my guy to do it?

quick cargo
#

Sure but I'm about to sleep so won't respond for a bit

honest dock
#

All good champ, thanks

native tide
#

so what this code is doing its switching day with case two day 2 is = tuesday (case 2)

#

switch (expression) {
case n1:
statements
break;
case n2:
statements
break;
default:
statements
}

wicked tide
#

Wrong channel (wrong Discord?). And switch statements normally will fall through (execute) the cases starting from whichever it initially matches.

native tide
#

but this is help with js read channel info

#

so what this code is doing its switching day with case two day 2 is = tuesday (case 2) am i right about this?

wicked tide
#

but this is help with js
Sure. You also could've just searched that statement up and not pinged a user which clearly stated that he was about to sleep 40 minutes ago.

native tide
#

lmao i never read that tho

#

so my bad

#

Sure. You also could've just searched that statement up and not pinged a user which clearly stated that he was about to sleep 40 minutes ago.
@wicked tide alright my bad about that i never read that cause my pc battery died so sorry bout that

wicked tide
#

I have no damn clue what you're asking about, being honest. I cannot decipher what you're asking. Fix your english and example.

native tide
#

do u know js?

wicked tide
#

Sure. But switch statements aren't just Javascript.

native tide
#

well im learning that in solo learn

#

in javascript course in solo learn lmao

#

wait i read ur thing wrong @wicked tide

#

im talking about js

wicked tide
#

Technically the switch statement you provided could go straight into Java, is all I'm saying. It might go into C# too, and a couple other languages. Still, no idea what you're trying to ask.

#

Does anyone here have an idea as to why this element has a height of 0? It's a Skeleton component in Vue. It might have no content inside, but it refuses to expand the height.

#

I've tried height: 100%, font size, min-height (as shown) etc. The element above has a height of 24px, so that can't be the problem.

fossil swift
#

PermissionError: [Errno 13] Permission denied: '/flask_session' im getting this and its infuriating, I've been tring to fix it all day.

  • www-data has access to flask_session
  • python directory is correctly set
native tide
#

can someone tell me whats the diff with

#

document.write("Hello World") and console.log("Hello World!")

warped timber
#

uh

#

they are very different

#

document.write writes html to the DOM

#

console.log prints text to the console

#

don't use document.write unless you have a good reason to

#

console.log is usually used for debugging

#

@native tide

dawn heath
spark rover
#

ok so I have a django rest framework app thats getting fairly big and we've got a repeated problem where we want the serializers to have different fields for normal users, admins and creation, we've ended up with viewset abstractions to make it a little nicer, but it feels like this problem must have come up many times before to other people, is there a better way of doing this?

versed python
#

maybe you can override the get serializer method on the viewset and then add conditionals there, and return an appropriate serializer there? @spark rover

spark rover
#

we already do that with some viewset base classes we defined, maybe its the only way, it just feels really hacky to have this many serializers

versed python
#

don't serializers have a get fields method?

spark rover
#

I'll have a look at that, thanks

versed python
#

you're welcome

vestal hound
#

ok so I have a django rest framework app thats getting fairly big and we've got a repeated problem where we want the serializers to have different fields for normal users, admins and creation, we've ended up with viewset abstractions to make it a little nicer, but it feels like this problem must have come up many times before to other people, is there a better way of doing this?
@spark rover I too had this problem!

#

what I ended up doing was creating a subclass of Serializer which, when initialised, takes a keyword argument allowing you to specify what fields you want

#

(basically)

#

and in particular, for my usecase there was often nesting (usually only one level, but still)

#

so there was also the ability to specify whether I wanted to use a child serializer or just the normal PrimaryKeyRelatedSerializer

versed python
#

Guys can anyone tell me what is the equivalent of logging that we do in python but in Javascript?

#

i am not talking about console.log

#

i actually want the data/errors to persist

#

not unless you have a special use case and need to do that. Why complicate things when the easier one gets the job done? import this @glacial night

#

yep @glacial night

paper canopy
#

So, im making a blog and im working on the profile pic feature rn. I've ran into a problem where the specified picture will show up on the web site but not the default picture I have set to

native tide
#

what module do you use for using google's oauth2?

vestal hound
#

is it a good idea to do /products/id/reviews/ or just show all reviews as a object inside product instance?
@glacial night depends, really.

#

on what? amount of reviews? @vestal hound
@glacial night not really

#

more like your workflow

#

for example

#

how often will you need

#

just the product?

#

how does this align with your conventions

#

for your other endpoints?

#

etc.

#

honestly this is the kind of thing

#

you can try yourself

#

and after a while

#

figure out

#

I would say both approaches are viable

#

okay

#

if you're not in a rush

#

I'd suggest

#

you pick one

#

and try it

#

experimentation is how you learn

vestal hound
#

what do you mean

hearty shore
#

hey i am very new to web development. i just wanna know where to start.

vestal hound
#

so like

#

double nesting basically

#

just

#

use serializers in your serializers

sharp wraith
#

what are the different coding format which sanitized the user inputs

past cipher
#

change js to py for python code

#

same for html, css etc

gleaming basin
#

hai anyone here

amber parcel
#

ask away

proper trench
#

hello

gleaming basin
#

hi i have a prob with an html templTE

proper trench
#

what's the problem with it?

gleaming basin
#

w8

#

sending

proper trench
#

ok, idrk what that is

gleaming basin
#

wait

#

it emas

proper trench
#

ok

#

?

#

!

gleaming basin
#

here ya go

#
<!DOCTYPE html>
<html>
  <body>
    <header>
      <div class="container">
        <h1 class="logo">danoxzilla's web app</h1>
        <strong><nav>
          <u1 class="menu">
            <li><a href="{{url_for('home') }}">Home</a></li>
            <li><a href="{{url_for('about') }}">About</a></li>
            </ul>
          </nav></strong>
        </div>
      </header>
      <div class="container">
        {%block content%}
        {%end block%}
      </div>
    </body>
  </html>
#

hello?

proper trench
#

hello

gleaming basin
#

heres ma code

proper trench
#

ah

#

gime a sec

gleaming basin
#

ok

proper trench
gleaming basin
#

how did u go check it

#

wut how

proper trench
#

just copy paste it into HTML file and open it

gleaming basin
#

u hacker?

proper trench
#

not that hard

gleaming basin
#

just copy paste it into HTML file and open it
@proper trench i did dat man

proper trench
#

ok, do you use VS code?

gleaming basin
#

no

#

atom

#

here ay go ma s=error

proper trench
#

ur running off of a local server

#

not just a basic file

#

just open ur html file with crome

gleaming basin
#

ok

#

i use microedge

proper trench
#

use that then

gleaming basin
#

it says file not founf