#web-development

2 messages · Page 106 of 1

native tide
#

the client stores it, not the server

#

scalability reasons, with a million users at a time storing all those cookies builds up

#

whether that really matters.... GWworkshopAkaShrug

#

so your server would simply take cookie, give jwt, then you are done no more storing no sessions, nothing. and the client just sends jwt on each req until they refresh or close tab or something which causes them to have to send cookie again, so mostly useful in a spa or something

silver shell
#

@native tide so you are saying you would store session data inside your jwt?

native tide
#

ive never actually used session cookies, what exactly are you trying to get at by 'session data'?

foggy kettle
#

I have a problem...whenever I create any react project on my desktop..whenever I save changes in my vs code editor it does not automatically comes to the browser I always have to refresh first and then I am able to see the changes
This is not a problem as such since I am able to refresh manually and do my work but still

native tide
#

if you used create-react-app it should autorefresh you or at least it does for me GWworkshopAkaShrug

#

yeah for me it autorefreshes too but im on pycharm

clear arch
#

Can someone help me out with templates?

native tide
#

vscode for me and it autorefresh. it shouldnt matter what ide GWworkshopAkaShrug

hallow thistle
#

Need Help in Flask Mongoengine

native tide
#

@clear arch whats the question

clear arch
#

I made all the script src, href, img src, src static but it still doesn't work

#

I also did {% load static %}

native tide
#

send the code

clear arch
#

well I was following a course so I download the templet

#

should I paste it

#

!paste

lavish prismBOT
#

Pasting large amounts of code

If your code is too long to fit in a codeblock in discord, you can paste your code here:
https://paste.pydis.com/

After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.

clear arch
native tide
#

Set your static directory in settings.py STATIC_URL = '/static/' and store all of your static files in a static/ directory

clear arch
#

STATICFILES_DIR and STATIC_ROOT did that

native tide
#

and static_url?

clear arch
#

STATIC_URL is '/static/' only

#

I didn't change it do I need to?

native tide
#

what directory are your static files held in

clear arch
#

I have a project folder and in that I have static folder

native tide
#

hmm I dont know what else you can check...

clear arch
#

want the error?

native tide
#

guys im pretty new in this subject, someone can help me where to start?

#

I'm getting an error when I save to my serializer. The "username" gets saved to my model's email field, the "email" gets saved to my model's password. How can I solve this?

#Serializer
class UserSerializer(ModelSerializer):  # In DRF serializer validation is done serializer-side
    class Meta:
        model = Users
        fields = ["username", "email", "password"]

    username = CharField(...)

    email = EmailField(...)

    password = CharField(...)

Model (extends Django prebuilt User class)

class Users(AbstractUser):
    notebook = models.ForeignKey(Notebook, on_delete=models.CASCADE, null=True, default=None)
    USERNAME_FIELD = 'username'
    EMAIL_FIELD = 'email'
clear arch
#

It says Not Found in all of them

#

omg

#

@native tide I typed STATIC_DIR and forgot S omg

#

this debug oof

native tide
#

ok

native tide
#

I have implemented a chat application using Django Channels. How do I now extend to use audio/video call? What I have searched for, people are saying about WebRTC but I can't find any resources (for Django).

#

From what I understand by reading is that you can also send video data to the server from Client A and then from server to Client B (but WebRTC is direct client a to client b, less latency).

#

Latency is not an issue here though, I am only trying to learn

summer wyvern
#

Hi

#

there is no Manage.py file in my django directory

#

I have searched everywhere

#

hello?

livid isle
#

Hey guys web dev noob here

#

what exactly is the difference between an API, Framework, and Library

#

im so confused

summer wyvern
#

a Framework creates websites

#

web framework like Django or Flask

#

a Library is something you import

#

example: ```
import random
from time import sleep

livid isle
#

yeah but you can interact with external databases and servers with APIs as well as libraries so whats the diff?

summer wyvern
#

librarys are libraries of code

#

API connects to web such as Plex API will conecct to a Plex Server

#

or Pastebin API will connect to pastebin

#

so you can automate stuff

#

or find information

livid isle
#

what about selenium?

summer wyvern
#

that automates stuff

livid isle
#

isnt that similar to Plex API?

summer wyvern
#

I dont think so

#

Plex API connects to plex only and finds info from plex only

#

Selenium automates web stuff

#

like button pressing

livid isle
#

what about the requests library?

summer wyvern
#

idk]

#

never used that

#

recap

#

Web Frameworks - create websites and servers

#

Libraries - contain code which can be helpful when creating a project

#

API - connects to web apps on the internet to automate or find information

#

got it @livid isle

summer wyvern
#

Hi
there is no Manage.py file in my django directory
I have searched everywhere

devout coral
#

@summer wyvern just make a new project then copy the manage.py

#

You will need to change the project name but that is all

summer wyvern
#

reinstall django?

#

I installed Django in a venv

devout coral
#

Just make a new project. And do startproject so it generates the manage.py. Then copy that manage.py to the project you already have.

#

On a different project.

summer wyvern
#

make a new Pycharm project

devout coral
#

Yes

summer wyvern
#

ok

#

and then do the command startproject

summer wyvern
#

@devout coral

devout coral
#

@summer wyvern You get this figured out?

summer wyvern
#

no

#

I created the project

#

now what do I do

#

@devout coral

devout coral
#

copy the manage.py file that is there to your project that is missing it

#

Then change the name of the project inside that manage.py file to match the current project

summer wyvern
#

do I have to install django in the other project

devout coral
#

@summer wyvern How did you startproject without the django library installed?

summer wyvern
#

I have installed Django again

devout coral
#

ok?

summer wyvern
#

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

#

I tried in both projects

devout coral
#

That is not the full command to start a project. Is this your first django project?

summer wyvern
#

yes

#

I have never used Django before

summer wyvern
#

I have been following a tutorial

devout coral
#

What tutorial?

#

It did not tell you how to start a django project?

summer wyvern
#

buildwithpython Django Tutorial

#

he showed how to install

#

start a venv

#

and start the server

#

with manage.py runserver

devout coral
#

Did it not show him setting up his project?

summer wyvern
#

he started a new project

devout coral
#

he never ran a django-admin command?

summer wyvern
#

nope

#

it was a old version

#

maybe it changed

devout coral
#

Must be a bad tutorial. Would you llike me to show you a good tutorial to follow?

summer wyvern
#

its a very good tutorial. I was reccomended by many people

devout coral
#

Apparently not... You got lost in the first few minutes..

devout coral
#

That is django 2.1 ....

summer wyvern
#

yes

#

ik

devout coral
#

So why are you learning from something out dated?

summer wyvern
#

is it changed now

devout coral
#

Django had a MAJOR change.

summer wyvern
#

ohhh

#

ok

#

normally I follow old tutorials as long as there wasnt a big change

#

but I follow new tutorals now

#

im going to fin a nw tutorial

devout coral
#

@summer wyvern Use that tutorial

#

It is really good and even goes into deployment

summer wyvern
#

ok

#

thanks

vapid acorn
#

Imagine having a blog and you have a text-area.
The user types in:
"This is so
cool"
Then you put the via post request data in a p tag like following
<p>{{text}}</p>

Oh no, the data is not formatted at all, and the p tag gives a f*ck that the text has \n and \r tags!
How would one handle this, is there like a format:true; or sth or should I use another tag?

#

The text I get out of the text area:
I have some\r\ndummy text\r\nto try with \r\nnewlines
(I printed the post-request content)

#

Ok i figured it out

#

white-space: pre-line ....

#

in a span

dapper tusk
#

what I did is have a property on the Post object that gives you the text as a list of lines

{% for line in text %}
<p> {{line}} </p>
{% endfor %}
vapid acorn
#

would work, thank you, but I think the solution I found on the internet is a bit more elegant

native tide
#

hey guys who learnt django / flask, did you actually get a job from it?

shy holly
#

@native tide yup

native tide
#

@shy holly if you don't mind me asking... what sorts of stuff were you doing in it? I plan on emailing some companies regarding internships and was just wondering 😄

shy holly
#

do u have projects done ?

#

I started doing free projects for my uni, and then they hired me

native tide
#

yeah, soon I will have one project done with Django backend + React fronten

shy holly
#

That's cool

native tide
#

oh nice

shy holly
#

then yea find a company that are looking for developers, and show them ur work

native tide
#

Ok, sounds good. I'm going into university next year so I have some time to work on it 😄

shy holly
#

yup good luck!

native tide
#

Thank you 🙂

tardy heron
#

I'm planning on using jwt claim to bind a token an address. Does that make any sense? Can I add something to request header with nginx? add_header directive adds to response header (i think?)

static harbor
#

how can I write mongod query in while loop, for example
I am trying to implement this

A related to B
B related to C
C related to D

and user enters A and D

then my program will output something like A>B>C>D

I have db str with fields "main", "relation", "second"
so when user enters a name (A) it will find in which main it is and then query it's second in loop till we able to find D

hazy night
#

Has anyone implemented a working contact page to send emails to their own email? I managed to get local and yahoo stmps working but the contact email has to be a yahoo email for me to receive it

hard sonnet
#

any help please? Im trying to make connection betweeb flask_socketio and react native socketio client, I have problem importing flask_socketio, it gives me error: No module named flask_socketio, I have tried reinstallning flask_socketio twice, rebooting rpi but nothing helps, here is my code:

#

!code

#
from flask import Flask
from flask_socketio import SocketIO, emit
 
app = Flask(__name__)
 
@app.route('/', methods=['GET'])
def hello_world():
    return "Hello World"
 
if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5005)
vapid acorn
#

I have a question on a django project.
I have an app called site and I want to redirect from ip:port/ to ip:port/site/
How would I do that (without having an extra app for that, and using their view to redirect)

devout coral
#

@vapid acorn have you tried using redirect method?

vapid acorn
#

how do you mean that, what redirect method, and where would I place it

#

directly in urls.py (in the project, not the app)?

#

ok I have and idea, let me try

sterile peak
#

Guys when do we use django rest framework??

devout coral
#

@sterile peak Whenever you want to make a rest api

#

@hazy night What exactly do you need help with. I do not understand the issue

sterile peak
#

@sterile peak Whenever you want to make a rest api
@devout coral so with the help of django rest framework I can use django as a backend and reactjs for front end, am I correct

devout coral
#

@sterile peak Yes but are you trying to make a website? Usually api's do not have a front end.

sterile peak
#

@sterile peak Yes but are you trying to make a website? Usually api's do not have a front end.
@devout coral I mean I can use those API to get data from my db right?!

#

And show it to user using front end frameworks

hazy night
#

@devout coral I’m built myself a contact page with yahoo’s stmp settings with name email and message content(finally just got it to work). But now When a user inputs their email to send a message to my email it HAS to be a yahoo email for me to receive it (gmail, live, etc does not work).

devout coral
#

That is typically what an api is for but it seems like you are trying to just build a website. So if you just want a build a website with a front end and a backend just use plain old django

sterile peak
#

@devout coral I’m built myself a contact page with yahoo’s stmp settings with name email and message content(finally just got it to work). But now When a user inputs their email to send a message to my email it HAS to be a yahoo email for me to receive it (gmail, live, etc does not work).
@hazy night I think it is due to some security settings , does Yahoo offer no other documentation to check it?

devout coral
#

@hazy night You want the user to send you an email from your site.... ? Confusing. Give me some more context please.

Are you trying to set up a way for the users to send you a message through your website? If so you would not use the users email. You would use your backend's email to send you the email and ensure that your send an email to their email if you need to respond.

hazy night
#

@devout coral Would I be able to dm you the code for my setting and views etc so you can see and point it out ? I’ve been on it for a week now and decided to reach out

#

Yahoo unfortunately is quite dry on documentation. Only really give me settings which is enough but I’m confused as why it’s not sending properly @sterile peak

devout coral
#

@hazy night Sure

sterile peak
#

@hazy night you've used Yahoo's SMTP settings so I think it would only work with Yahoo. To get it to work depending on user's emails then you need to incorporate other emails SMTP settings and then use them accordingly based on user jnput.

Anyways, I am not sure what exactly is you are trying to accomplish so I may be completely wrong.

devout coral
#

@sterile peak Yeah there is no need to have the email come from the user directly and you would not be able to do it since you will not be able to authenticate to the smtp server unless the user gives you the password. What he needs to do is just have the messages be sent from the server and then have somewhere in the email body who it is from.

sterile peak
#

@devout coral yes that's what I feel too! Did you take a look at his code

devout coral
#

Not yet

sterile peak
#

alright man, if you find it interesting please let me know too.

honest rock
#

so if this is a python server and this is the web-dev section then is there we talk about web django?

sterile peak
#

Currently I am working on accessing IBM Lotus notes using Python so I think it might be helpful

devout coral
#

@honest rock Among other things

honest rock
#

ok? @devout coral

sterile peak
#

@honest rock ?

honest rock
#

I am so confused

#

but I am liking this server

sterile peak
#

About?

honest rock
#

nvm

#

bye

snow sierra
#

heey

#

i just added 'partner_url' << then makemigartins, then migrate... there was not something new, i deleted last migartion files, after my row added in admin. but i got message "no such column: webdir_partners.partner_url" i know if i save to new db.sqlite everything will work good..

devout coral
#

@snow sierra You do not delete migrations unless you are deleting the database

snow sierra
#

@snow sierra You do not delete migrations unless you are deleting the database
@devout coral there is another way..

#

i want add third row in table, how?? without any issues..

#

i mean Column in db table (Partners)

still python
#

hi

devout coral
#

@snow sierra All you had to do was add another property to that class and run migrations

#

The ORM would handle the rest

#

@still python Hello

#

@still python This is the channel for web development

#

No worries

native tide
#

Am I doing this right?

A user signs up on my website via an API. The API provides them a token for token auth. Then that token is stored in a cookie and on any future requests (as long as the cookie is there) the token will be placed in the header of my client requests

zealous siren
#

@sterile peak Consider lighter framework for pure Rest API like Flask/FastAPI

snow sierra
#

@snow sierra All you had to do was add another property to that class and run migrations
@devout coral i said it does not work man... i just added column manualy in DB.... bye.

devout coral
#

Because you deleted your migrations... you would need to delete your database then re run the migrations.

hazy night
#

@hazy night you've used Yahoo's SMTP settings so I think it would only work with Yahoo. To get it to work depending on user's emails then you need to incorporate other emails SMTP settings and then use them accordingly based on user jnput.

Anyways, I am not sure what exactly is you are trying to accomplish so I may be completely wrong.
@sterile peak So would i have to add all the smtp settings for multiple types of emails for a user inputted email to be sent to my email?

#

so its a contact page, user writes email and their name plus message and i receive their email (to my email). its only working with yahoo emails at the moment though is my issue im not sure if im explaining poorly

vapid acorn
#

Someone who wants to help me testing my website ?

#

It's just telling me what looks awful and what is all right

#

The link, not supposed to be ad

devout coral
#

@vapid acorn Says it cannot be reached

vapid acorn
#

A timeout or any other error message?

snow sierra
#

it works

vapid acorn
#

ok

snow sierra
vapid acorn
#

that's good

snow sierra
#

where it is hosted?

vapid acorn
#

on my computer

#

currently

#

but I think I will move it to my Raspberry PI

snow sierra
#

is not bad idea

#

what type of server?

vapid acorn
#

I use django and just do runserver 0.0.0.0:8010 with portwarding

snow sierra
#

nice :)))

vapid acorn
#

But I really struggle making sites look good

#

and i use noip.com to get and domain (instead of the long ip with port) also so my ip doesnt change

snow sierra
#

for testing is good ..

#

can you try run games in browser windows?

vapid acorn
#

yeah, the domain isnt beautiful tho (blabla.hopto.org) but who cares

snow sierra
#

no one 😄

vapid acorn
#

oh I thought about that (btw im on ubuntu) but they are pygame and not js games, which would be easier

#

I will look into that though

devout coral
#

@vapid acorn Oh it is being blocked in my network

vapid acorn
#

maybe because it is http not https

#

or just because it isnt in like a google index or sth

snow sierra
#

tor it @vapid acorn

vapid acorn
#

what do you mean?

snow sierra
#

oops.. wrong chat

vapid acorn
#

oh ok lol

devout coral
#

Yeah because it is not indexed.

vapid acorn
#

oh ok thanks

gentle ingot
#

Is there a way to import bootstrap into a custom css file?

native tide
#

@import url("stylesheet")

#

pretty sure this should work

bright spindle
#

how do i serve a single static file in caddy for a directory like url/path/

#

theres barely any guides online

gentle ingot
#
@import url("https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css");

.primary-btn {
    color: white;
}
``` This doesnt change the color of my button text to white. Am i importing it wrong😅
#

wait. i forgot to add the style sheet to my html 🤦‍♂️

devout coral
#

@gentle ingot remove the import and change it to.

.primary-btn {
    color: white !important;
}
#

And it is a good idea to import the css lol

native tide
#

!important override the cascade?

#

@devout coral

#

woops

devout coral
#

Uhh what?

snow sierra
#

!important! will always first and important for your css

native tide
#

"!important override the cascade?"

snow sierra
#

lol, little bich bot

native tide
#

im pretty sure i learned this but it was so long ago and i never used it

devout coral
#

Yes, it seems that is what he wants to do. Override what the primary-btn color is

native tide
#

cant u just use SCSS or something to change it?

#

or SASS

devout coral
#

Yeah but that would require to download bootstrap locally change it then compile it

native tide
#

yeah...

#

and?

snow sierra
#

also you can in html without any imports... <button style="color: white;")</button>

devout coral
#

He is clearly using the cdn...

native tide
#

ik

#

But i just think its not a great solution.

devout coral
#

So why have him go through the trouble of downloading it changing it, compiling it etc.

native tide
#

i mean its up too him

#

but if i was building production code its not what I would go with

devout coral
#

Yes it is up to him, if he is setting up a legit server yes he would have the local bootstrap copy change/add everything he needs for his application and go with it.

#

But it does not seem his main worry right now is this, you are correct though. Good Quality production code should go through the process of downloading, changing, compiling.

gentle ingot
#

Im just going through CS50 lmao. Didnt want to use inline styling if i could update what i needed to change in a css file

devout coral
#

CS50 will not expect you to download the boostrap scss. I suggest to go with the easier approach and include a !important

gentle ingot
#

Figured out why it wasn't working. My a tag was changing the color not the button

devout coral
#

@gentle ingot You have a button wrapped in an <a> ?

gentle ingot
#

I have the text wrapped in <a>

#

<button type="button" class="btn btn-primary"><a href="images.html">Image Search</a></button>

devout coral
#

Why are you doing that exactly? For the button appearance?

gentle ingot
#

Yeah the button tag is to make it look like a button and the a tag is to link it to the other page (havent learn js yet)

devout coral
#

Do the following instead

<a class="btn btn-primary" href="images.html">Image Search</a>
#

The button styling can be applied to any tag basically

gentle ingot
#

Huh, i guess that would be better since theres no real button functionality

#

Thanks

devout coral
#

YW

#

Is this pure html, css right now? Or are you building this with a backend?

#

Just curious

gentle ingot
#

Pure html and css

trim star
#

Is it a good idea to list supported file upload types on a web site? Or is that divulging too much information?

gentle ingot
#

Project 0 included python but like. Its an overview and not useful within context of the course

devout coral
#

@trim star Why not include it? I would say include it.

#

@gentle ingot Well good luck

trim star
#

@devout coral ok cool

#

Also, what is the best way to check that an uploaded file truly is in a supported format? I was thinking of reading a few bytes of the file header natively

snow sierra
#

it has many ways.

trim star
#

@snow sierra Well what currently happening in the project that I am contributing to is that they are just checking the content type of the request...but that can be bypassed, right?

snow sierra
#

example:

def validate_file_extension(value):
if not value.name.endswith('.pdf'):
raise ValidationError(u'Error message')

trim star
#

@snow sierra Thats worse than checking the content type right? Someone could just change the file extension

snow sierra
#

from FORM?

devout coral
#

@trim star By default django only checks the file extension. You can add some fancy stuff to try and read the file itself and see if it matches what you are looking for.

snow sierra
#

did you use Django forms or HTML?

trim star
#

@snow sierra they are using django forms

snow sierra
#

it has own security i guess

#

but let me test something

trim star
native tide
#

i could have sworn to god django automatically checks files not just extension?

gentle ingot
#

Sorry for the ping misread the comment.

trim star
#

@native tide I thought that too

devout coral
#

@native tide Nope it only checks the extension

native tide
#

¯_(ツ)_/¯

devout coral
#

Let me double check

slender moat
#

hey guys, does anyone know how i should deserialize with marshmallow, a database model that in one of its fields contains another database model?

native tide
trim star
#

There is a FileExtensionValidator but they specifically tell people not to rely on it as someone could just change the file extension

native tide
#

Also someone needs to build a better CAPTCHA library with images not just fucking text

slender moat
#

because right now, it's only deserializing the "root" object, and the nested objects don't get unpacked

native tide
#

lol...

#

they are using regex

devout coral
#

Yeah.

native tide
#

i mean i guess it gets the job done

#

But I remember my teachers telling me not to use regex for this sort of stuff...

devout coral
#

I mean if someone uploads a shell script but the file extension is .pdf what are they gonna do with that?

native tide
#

*programatic parsing"

#

Well it depends.

#

on so many things

#

might be able to execute it from with in the website by just searching it

#

u never know

devout coral
#

How will they execute it though if it has a .pdf extension?

native tide
#

...

#

good point lol

devout coral
#

They would need direct access to the file system in order to change that

#

and if they gained access to the file system you probably have bigger issues lol

native tide
#

Can I ask what u do snowball?

trim star
#

Yes, but its still an issue in my opinion even though there would need to be another vulnerability present

native tide
#

U can easily implement ur own method for doing it

#

all ud have to do is check the header wouldnt u?

devout coral
#

@native tide Sure... I am a month away from being the IT Manager at the company I work for.

native tide
#

i could wipe something up like that in 15-20 minutes probs less

#

yay!

trim star
#

@devout coral there could be a case where other vulnerabilities are present that can change file names/execute files

native tide
#

Congrats mate

#

IT or CS?

#

or self taught

devout coral
#

Thanks bro, self taught got me the job. But I went back to school and I finish next fall (IT).

snow sierra
#

it is very low level trick... i think django form default can handle like this tryies

native tide
#

Django seems pretty robust from what i've seen

devout coral
#

@trim star But then those are other vulnerabilities... I do not think you should worry too much about this tbh

trim star
#

U can easily implement ur own method for doing it
@native tide Yep! thats what Im thinking of doing...safely reading the first few bytes of the file to check file type

native tide
#

and for the most part i think u need to try to make it insecure "excluding js"

devout coral
#

@native tide May I ask what you do?...

native tide
#

I mean actually u only need maybe 5 lines of code.

#

Nothing lol

#

thats it

#

i dont even go to college anymore

#

dropped out

devout coral
#

Teaching yourself?

native tide
#

I struggle at committing to things

#

yeah lol

trim star
#

@trim star But then those are other vulnerabilities... I do not think you should worry too much about this tbh
@devout coral I know Im being paranoid lol

native tide
#

I find they teach garbage at school

devout coral
#

Nice, May I ask your age??

native tide
#

I'm 20

devout coral
#

Nice

native tide
#

@trim star
I don't think ur being paranoid

#

I'd implement one too tbh

#

just need to check to see its got the header of the file u actually want

#

if it doesnt delete it

devout coral
#

What sort of experience in web development do you have?

native tide
#

legit 5 lines of code lol

#

Not much

#

legit just front end for the moment

devout coral
#

I think he said he already is checking that

native tide
#

Havent touched django

#

but i intend on it

devout coral
#

@native tide Django is great. I have been developing with it for a little over a year now and let me tell you. It is great.

native tide
#

If any of u have some exp with solid and OOP i wouldnt mind some feedback on code

#

Yeah ahaha
I'm looking forward too it

#

Had a guy tell me to just use flask but that seemed daunting

mortal mango
#

Does anyone know why my CSS doesn't show up on my computer? Everything works fine on my VPS but it doesn't on my computer. This same issue happened on my VPS but I fixed it with permissions. I can't figure out why it's not working on my computer tho.

native tide
#

We need more information

#

Where are your web files?

#

whats the file structure?

snow sierra
#

Does anyone know why my CSS doesn't show up on my computer? Everything works fine on my VPS but it doesn't on my computer. This same issue happened on my VPS but I fixed it with permissions. I can't figure out why it's not working on my computer tho.
@mortal mango incorrect path (my first opinion)

native tide
#

Most likely just in the wrong directory/pointing to the wrong file.

devout coral
#

@native tide The problem I find with flask is that if you are going to make a website might as well use django since you won't need to install everything individually

native tide
#

I think it would be good for micro services

#

Like if you need to build a separate site for payments.

hybrid bobcat
#

i need help with a package called django-spirit ;-;

native tide
#

and then redirect too it.

devout coral
#

@native tide I think flask is the king of microservices tbh

snow sierra
#

flask is a mother of python web :d d

native tide
#

I'd probs not even bother though.
I'd just build a backend service using python and then

#

well

#

allow django to talk to it

devout coral
#

The overhead for it is small compared to django. Once you add all the functionality that django has though the performance difference is negligible.

native tide
#

Yeah well

#

u can scale with anything

#

It doesnt matter what ur using long term

#

because scale is more about u and what ur doing in other places.
Like ur infastructure is just as important

devout coral
#

Yeah, but I think the selling point of django is just development speed. If you know it you can whip up a site in no time

native tide
#

I mean u gotta optimize code for it but...

#

How long do u think u could put together an ecommerce site?

#

like the backend

mortal mango
#

@mortal mango incorrect path (my first opinion)
@snow sierra no I checked

native tide
#

no libs

mortal mango
#

it's correct path

snow sierra
#

it's correct path
@mortal mango screenshot it

native tide
#

this is why u use docker 😂

devout coral
#

@native tide IDK, maybe a 1-2 full workweeks not including deployment.

snow sierra
#

and what OS do you using?

native tide
#

is that 8 hours a day?

#

thats mvp right?

devout coral
#

Yeah.

#

mvp?

native tide
#

minium viable product.

devout coral
#

Yes

#

LOl

native tide
#

gg

#

lol

#

thats what i expected tbh

#

God dam gotta hire online code auditors rip

devout coral
#

Hahaha my front end skills are like uhhh.... not great

native tide
#

and hope they dont just run bandit or some trash

#

yeah front end be eh

#

I thinking ima just highly customize a framework like bulma/bootstrap using sass

#

so it doesnt like like im using it

#

and then add extra classes if i need them

devout coral
#

@native tide I am currently working on a pretty large django project and I am not even editing the bootstrap directly... bad practice but I just want to get v1 rolling

#

@native tide Honestly, I do not think anyone would care if they noticed you are using it.

mortal mango
#

{% static 'css_files/index_style.css' %}

#

will this only work on linux?

devout coral
mortal mango
#

that looks pretty good tho

devout coral
#

Thanks

snow sierra
#

@native tide How bootstrappy does this look?
@devout coral does those EXPORT icons works?

#

or what is it

native tide
#

i think it looks fine lol

devout coral
#

@snow sierra What do you mean if they work? Like function on the website?

native tide
#

not sure how much like bootstrap it looks

#

but it really doesnt matter

#

unless ur trying to enter some market and standout

#

at the end of the day the customer doesnt care

devout coral
#

@native tide It will be an internal tool

snow sierra
#

@snow sierra What do you mean if they work? Like function on the website?
@devout coral Left side of 'Total Ppints'

native tide
#

as long as it doesnt look like trash

devout coral
#

@snow sierra Yes everything functions

snow sierra
#

and what it do?? Print Version? pdf? excell

native tide
#

do u know what sudo elements are?

#

like ::before and ::after

#

@devout coral

devout coral
#

@snow sierra They export pdfs, there are titles for everything.

#

@native tide Yes, why?

native tide
#

Was just wondering ahaha

#

I feel like front-end is an art sorta thing

#

u really gotta use it to learn it

devout coral
native tide
#

yeah

devout coral
#

Front end is definetly an art lol

#

I am not about that life

native tide
#

I am

#

i gotta be rip

#

luckly if u put enough time into anything ital turn out good

#

even if ur complete trash

devout coral
#

I wish I had screenshots of my earlier account page so you could see the difference

native tide
#

pure bootstrap?

devout coral
#

This site is bootstrap plus my custom css

native tide
#

What about infastructure?

#

what do u knoiw about linux mysql etc?

#

it does look a bit bootstrappy

#

i think its manly the cards

#

the rounded corners and box shadow are it i think

#

but maybe im just overthinking it

devout coral
#

Well I actually maintain a SQL database in my day job so I know a good bit about SQL server but I am not a wiz making manual queries

#

Linux I only really know ubuntu

#

But server wise I maintain a few Microsoft servers

#

And yes my current IT Manager refuses to switch over to Microsoft Server 2016 from 2008R2 at one of the locations (do not ask me why, this is why they are having him retire lol)

#

@native tide Yeah, but I really wanted the shadow effect. I did not like what I had before which was greyish background and the white boxes.

snow sierra
#

can you guys tell me i18n alternative methods ??

devout coral
#

@snow sierra i18n?

snow sierra
#

@snow sierra i18n?
@devout coral one more Languages for website..

devout coral
#

@snow sierra Yeah that is tough. I remember when I was doing some IT consulting for a church they wanted a website built Spanish and English the firm that was doing the wesite design was basically charging double for the site since they would simply translate everything and build another site. Not sure if that is how you are supposed to go about it but that is what that firm was doing.

snow sierra
#

Found the before
@devout coral can you screen urls.py ?

devout coral
#

@snow sierra Like a screenshot of all my routes?

snow sierra
#

i don;t want something bad for you and for your code lol :d

devout coral
#

I am confused.. What did you want? Screen shot of the urls.py?

snow sierra
#

yes

devout coral
#

sure

#

@snow sierra

snow sierra
#

👍 👍 👍 👍 👍 👍 👍 👍 👍 👍 👍 👍

devout coral
#

?

#

What were you looking for?

snow sierra
#

is not it?

devout coral
#

What do you mean?

snow sierra
#

i never used include(file) in path() .. 1 more step in my mind

devout coral
#

That the urls.py for the project (the one with all the includes) should be in the same directory as settings.py?

raw imp
#

Why isn't nodemon working anymore???
I installed it like 2 days ago and now when I try and use it it won't restart the server after saving my code????

#

Please help me or I might punch my screen.

devout coral
#

@snow sierra Oh yeah, I do that to better organize the project. This project is not small so if I put everything in the projects urls.py it would be hectic to decipher

snow sierra
#

That the urls.py for the project (the one with all the includes) should be in the same directory as settings.py?
@devout coral i mean it is new for me .... i don;t know is it better or not 😉 just good idea

devout coral
#

Oh yeah, it makes sense if you have multiple apps to better organize code

#

I currently have 3 apps and v2 will have 4 apps. v3 will have 5.

#

Imagine having all those routes in one file lol

snow sierra
#

also we can , **** from other_project import urls as u1 ****

#

of course it is very good for big projects , but i must start write like that 😉

#

in my little projects too ..

#

OK.. lets see Adam's issue :/

#

Why isn't nodemon working anymore???
I installed it like 2 days ago and now when I try and use it it won't restart the server after saving my code????
@raw imp don't know :X fckin node :d does it run in Virtualenv ??

devout coral
#

@snow sierra not sure why you would have multiple projects in one. If you want to first get split up your project that is what apps are made for.

raw imp
#

I'm super confused... it was working fine a few days ago. I havn't changed anything with the nodemon setup.
Just stopped working.

I tried removing all the node_modules and reinstalled all the dependency's. But that doesn't make a difference.
Looks like it isn't even installing, yet it can be run using npx nodemon -v

devout coral
#

Sorry bud, I have no clue how to help you.

native tide
#

@devout coral
lol like i said before

#

there is no problem with it looking like bootstrap

#

Customers dont know

#

unless ur a web dev...

devout coral
#

Yeah I know, but the first design just looked bad.

native tide
#

cause of bootstrap?

devout coral
#

The blue buttons the alignment

#

All of that

native tide
#

ooo

devout coral
#

No not bootstrap.

#

Did you see my before picture?

#

I posted it

native tide
#

yeah it looks dreadful

#

how much did u change css wise?

#

i think the main difference is more layout

devout coral
#

CSS wise a bit not too much. The biggest thing I guess css was the “cards” were not bootstrap cards and they had some animation which I removed.

#

The layout was the biggest thing.

native tide
#

o lol

#

what sort of animation

#

was it the pop up thing

#

where u hover over it and it gets bigger

#

cant remember the effect name

devout coral
#

Zoom yes

#

Lol

native tide
#

zoom

#

rip

#

Know much about SOLID and OOP?

#

or do u just make sure it works?

devout coral
#

I am confortable with OOP and nothing really about SOLID I will be getting my CS degree soonish to simply learn algorithms and software design a bit better

native tide
#

Have u ever considered maybe just reading some books on algos and software deisgn

lavish prismBOT
#

Hey @native tide!

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

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

native tide
#

hm

#

Data Structures and Algorithms in Python

devout coral
#

Well I have a long term plan. I want to have my PhD in CS to teach college level for “retirement”

native tide
#

is a great book

#

lol

#

sure is long term

#

SOLID be sorta annoying imo

#

the examples people give u are so impractical imo

#

following SOLID rigidly can lead to some pretty terrible code as well

devout coral
#

Yeah, I do not think people really do that

native tide
#

Do what?

devout coral
#

Follow it rigidly. And by people I mean some software companies

native tide
#

google did it lol

devout coral
#

Well damn

native tide
#

it was a specific project

#

Cant remember what

devout coral
#

But for most thinks I think they take from it and adapt it to their project

native tide
#

but theres a rule that code should be open to extension but closed to modification

devout coral
#

You live in the US?

native tide
#

pretty much ur supposed to add things with inheritance for the most part and it can lead to some spectacular class hierarchy

#

No, I live in AU

#

*Australia

devout coral
#

Ok cool.

#

What sort of projects have you completed?

native tide
#

lol

#

not many

#

Give me a bit gotta go study

devout coral
#

Ok cool

native tide
#

bootstrap is great for having your layouts

#

its the standard

devout coral
#

I would hate doing front end without bootstrap

native tide
#

@native tide
u could use flexbot

#

in fact i think they might use flexbot

#

you mean flexbox?

#

or just use bootstrap... where you can have flexbox also

#

yeah rip typo

#

i dont know how the hell i got that confused

#

it happens

#

Bootstrap is OK i mean

#

I'm not a big fan personally.

#

I like smaller frameworks.

#

Something that only provides css components.
I think its better to use it so u dont have to reinvent the wheel and then just highly customise it.

#

and u cant rely on css frameworks for there js

#

@devout coral
As for your question about my projects.
I coded a mod manager (for minecraft) it was trash the code was dreadful and all it did was download files from curseforge and place them in a directory.
I also attempted implementing IRC but gave up on that for reasons I wont get into.

Right now im writing a noughts and crosses with network capability.
Was also going to turn it into a discord bot after posb.

#

I'd share my github but deleted it lol

#

¯_(ツ)_/¯

devout coral
#

@native tide that’s cool

#

I’d like to make a multiplayer game but I am really focused on this current project.

native tide
#

If I'm using Django token auth, can I still use the functions login() and logout() despite them being session-based? I have a React frontend so I don't think it'll work anyway...

viral slate
#

Hello, anyone pretty good with Flask?

native tide
#

@viral slate Well it's the web-dev channel so I'd hope so

bleak bobcat
#

I'm sure there are a lot of people in this world who are pretty good with Flask yea

viral slate
#

lol awesome, I'm going to try to start a Flask project and I was looking for someone for pointers

native tide
#

what's the question

viral slate
#

So I'm working on creating a table with stock information from pulling info from a .csv file and api call requests. Using pandas I'm able to pull the data that I want into a pandas dataframe, but I'm unsure of how to then pull the api data and combine it with the data that I have in my pandas df.

#

I already have a source and api for doing the calls so I've got the source of data figured out. I'm just unsure If I need to move my pandas dataframe into a sql database and then somehow add the api data or what...

native tide
#

Ok, so you could have your API call for data, save that in a DB with a timeframe, then you can display that information. Then you can have an API to convert your pandas DF into your DB to combine the two data sources.

#

I wouldn't know how to go about that with Flask though, I'm not that good with it.

viral slate
#

I haven't started with flask yet so I could go with django. I'm just trying to get the data for the table sorted out an then put it on django/flask. I just said flask because it looks more beginner friendly.

#

My question about the api data is that it is dependant on the stock tickers I have saved in my pandas df so it will know what to pull.

vestal hound
#

@viral slate I'm confused

#

are you asking about combining the data or about how to build a backend/frontend using it?

viral slate
#

Yeah, right now I'm working on the backend.

vestal hound
#

okay

#

what do you want to do with it?

viral slate
#

I have a downloaded csv file from my brokerage and then I use pandas too strip out the stock tickers, number of shares, and my cost basis. I'm using FMP api to call financial informaiton. I want to then pull info such as last price, etc. from using the stock tickers from my pandas dataframe and then turn that into a table for a web application.

haughty turtle
#

On mobile right now but what does this return.

categories = Category.objects.all()

#

A list?

bleak bobcat
#

A queryset

haughty turtle
#

A queryset or set? I mean I could convert it to a normal set or list right?

bleak bobcat
#

You can think of a queryset as a "list on which you can do database operations"

#

Not exactly accurate but enough to get the basics

haughty turtle
#

categories = set(Category.objects.all())

#

I just want the list not perform any operations on them, would this work @bleak bobcat or I mean can I loop through that QuerySet just as I could a set or list?

bleak bobcat
#

You can loop through it as you would a list, don't convert it unless you have a very specific reason to

haughty turtle
#

Ok cool thanks

vestal hound
#

Ok cool thanks
@haughty turtle what do you want to do with it?

#

there may be a more efficient way

native tide
#

Hey guys after a user signs up / logs in, I save a token as a cookie in their browser. Do I have the right design, where I will include this token as a header in each request to be able to distinguish between users (and therefore provide the correct content for each)?

vestal hound
#

Hey guys after a user signs up / logs in, I save a token as a cookie in their browser. Do I have the right design, where I will include this token as a header in each request to be able to distinguish between users (and therefore provide the correct content for each)?
@native tide yes

native tide
#

Ok, thank you. I know that Django has some functions login(), logout(), but I have never used them and I believe they're based on sessions.

Since I'm using tokens this way, will those functions be useless?

haughty turtle
#

I just want to grab each item in the list to use for another var.

vestal hound
#

I just want to grab each item in the list to use for another var.
@haughty turtle yeah, how do you want to use them?

#

well I mean whatever you're doing will probably work

#

it's just whether there's a better way

haughty turtle
#

For items in Category:
Product.objects.filter(category__startswith=items)

#

On mobile can't indent correctly

#

@vestal hound

viral slate
#

@vestal hound so you think I should take my pandas dataframe info and put it into a database and from there I'll be able to add columns from pulled api data?

native tide
#

gm so knowledgeable bro

#

its crazy

#

should do some mentorship 😉

versed python
#

didn't all your homies love flask a few weeks ago?

native tide
#

yea. now all my homies love django

versed python
#

you should tell your homies about Bottle too

viral slate
#

why the change from flask to django?

native tide
#

Bottle is for goopies.

#

Idk lol just wanted to try django out

viral slate
#

Ive only heard of django and flask. I'm looking into flask more since I've heard the learning curve was lower.

haughty turtle
#
Product_Categories = {}
categories = Category.objects.all()
for I in categories:
    Product_Categories[I] = []
    Prod = Product.objects.filter(category__startswith=items)
    for p in Prod:
        Product_Category[I].append(p)```Although I will probably have to double check on me appending directly to the list just by calling the dict, on mobile will do so once on PC but going to pass this dict as a context through my view.
devout coral
#

@vestal hound btw, I figured out that celery issue. Apparently it’s a Windows problem with the worker and you need to set the ‘—spool’ property in order for the task to execute

#

@haughty turtle what exactly are you trying to do?

haughty turtle
#

Just organizing my products in a dict by category

#

Saving my code for later usage

devout coral
#

@haughty turtle I’m pretty sure you can do all that with one query and one loop. One sec.

onyx dock
#

does anyone know a good resource for using Marshmallow library? the docs kinda suck

native tide
#

@viral slate learning curve is lower but not by much. Django has inbuilt functions / models and other stuff which is easier to leverage compared to Flask, where you'll be looking at different libraries and different documentation to fill in what's not included (when compared to Django)

viral slate
#

@native tide so do you think I should start learning by using Django?

native tide
#

I personally don't think it matters. But if you want in-built functionality then go for Django. If you want more of a "free" experience use Flask. Whichever framework you learn, you get attached to it. I was attached to Flask and hated moving onto Django, but when I did I got attached to Django so it's my personal preference talking here

versed python
#

yeah all his homies love django

native tide
#

facts bro

#

homies backing django on foenem fosho fosho

#

react gang too wya

#

all my homies hate setState()

devout coral
#

@haughty turtle

organized_items = {}
items_list = []
items = Items.objects.order_by(‘category’)
for item in items:
    If items.category not in organized_items.keys() and items_list:
        organized_items[items.category] = items_list
        items_list = []

    else:
        items_list.append(item)

I am thinking something like this. Not sure how your models are set up but I think the concept still holds.

#

I hope I formatted that right. I’m on mobile so excuse poor indentation.

haughty turtle
#

SLoC increases then, is there a benefit to using that concept over the one I have?

vestal hound
#

On mobile can't indent correctly
@haughty turtle so you want one queryset each? or a big one

#

for loops in Django, unlike in pandas, are not almost always dodgy, but they can be

#

oh okay I didn't notice

#

your code

#

@vestal hound so you think I should take my pandas dataframe info and put it into a database and from there I'll be able to add columns from pulled api data?
@viral slate if you want it to be persistent, yeah

viral slate
#

@vestal hound would I be able to do with without a database and just work within pandas and then make a table on the frontend with info from the dataframe?

vestal hound
#

hm.

#

yes.

#

but what if your server goes down

#

how will you persist the data

#

@viral slate and will the dataframe be updated in realtime?

viral slate
vestal hound
#

okay

viral slate
#

What I have in red is what I have in the pandas dataframe and I need to be able to get something like the value from an api call

vestal hound
#

so yes?

#

to my question

viral slate
#

I don't beleive realtime is required.

vestal hound
#

okay, let me rephrase

#

will it be updated while the backend is online?

viral slate
#

I don't beleive that is necessary. As my thought is that I'll upload a fresh csv file for the web app to pull the latest stock tickers from and number of shares

vestal hound
#

okay, so what's your mechanism for updating the DataFrame in memory

viral slate
#

That I'm unsure of. Right now I'm basically at scratch.

vestal hound
#

why don't you want to use a database actually

viral slate
#

I think I'll have to and set it up locally to start my project.

vestal hound
#

like you don't have to but it's a bit of an icky way to do things

#

IMO, at least

viral slate
#

I'm going for the best method possible

vestal hound
#

yeah.

#

you'd need to learn some SQL, most likely, though

#

or do you already know it?

viral slate
#

I'll have to learn it. I have a dataquest.io membership for a year so I can hit up the SQL section. I'm just learning as I go.

#

I would like to know what you would think the smoothest route would be. From csv file to creating that table.

vestal hound
#

remind me

#

what backend library are you using again

viral slate
#

I don't have one set up at the moment. I'm trying to figure out the best route/path and go from there.

#

this is just some code that I have to edit down the csv to get the first few columns that I want to include in the table

#

I think I'll be leaning towards flask for the web development part

merry copper
#

does this make sense ?
@gaunt marlin yes! Thank you so much!

viral slate
#

@vestal hound thank you for trying to help me. I appreciate it

gaunt marlin
#

When you switch from home to games>brotastic, look at the change in highlight on the navbar.
@gentle ingot so you are using the nav bar for other templates and you want active bar to be highlight right? in template you can get the info of the url path with request.path to see which page you are on for example this is how i would do this in a jinja tempalte(used by django and flask framework):

{% if request.path == '/brotastic.html' %}
         <li class="nav-item active"><a>brostatic</a>
{% else %}
   <li class="nav-item"><a>brostatic</a>
{% endif %}

this is an example but you can write your own if logic in the templates to render

merry copper
#

@gaunt marlin it's not working.

gaunt marlin
#

@merry copper what not working? does it return error ? what is the result ?

merry copper
gaunt marlin
#

@merry copper can you post your code ?

#

row is a RowProxy class(models maybe)

merry copper
#

!code

lavish prismBOT
#

Here's how to format Python code on Discord:

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

These are backticks, not quotes. Check this out if you can't find the backtick key.

gaunt marlin
#

it's ` tick @merry copper

#

the one on under esc button top left

merry copper
#
def get_case_image(conn: DB, case_id: int):
    image_path_sql = str("SELECT \"image_path\" FROM \"Suture_image\" WHERE \"case_id\" = {} AND (\"image_type\" = '4' OR \"image_type\" = '1')".format(case_id))
    print(image_path_sql)
    image_path = conn.connection.execute(image_path_sql)
    image_path_list = []
    site_url = 'http://10.34.102.60/jupyter-suture/view/suture-api/'
    for row in image_path:
        image_path_list.append(siteurl + row)
    return image_path_list
#

and this function will use in

gaunt marlin
#

@merry copper try:

image_path_list.append(site_url + str(row))

instead

plucky tapir
#

on django for a budgeting app, if the user wanted to input their information

in terms of the database, should they update their information everytime there's a change, or create new posts each time?

merry copper
#
@app.get('/api/case-image/{case_id}')
def case_image(case_id: int):
    db = DB.init_db()
    image_path = DB.get_case_image(db, case_id)
    db.connection.close()
    return {'image_path': image_path}
native tide
#

Why not make a variable then append that variable into a list

#

Dont work like that?

merry copper
#

@merry copper try:

image_path_list.append(site_url + str(row))

instead
@gaunt marlin it works!

#

Thank you!

gaunt marlin
#

@native tide why would you make a variable and append it? when you can just append it? sound like 1 extra line and just create a random variable for nothing

native tide
#

Make the code clear and understandable

gaunt marlin
#

@native tide no it doesn't, to make code clear and understandable you can put comment in it

#

remember when you set a variable you assign it to an address in your memory, when you don't even use that variable for anything in the logic

#

so just wasted memory

native tide
#

Variable are useful Don't say you don't even use that , variables have it own purpose and variables hold sensitive information which can be later it's not waste of memory . Clear variable make the code easier understand .

#

U don't understand the importance of variables

plucky tapir
#

I can make my django project a rest api to use the data to make charts from javascript?

vestal hound
#

I can make my django project a rest api to use the data to make charts from javascript?
@plucky tapir yup!

#

@native tide why would you make a variable and append it? when you can just append it? sound like 1 extra line and just create a random variable for nothing
@gaunt marlin it depends.

#

I could see a reason to do that

#

shorter is not always better IMO

#

also the memory saving argument is p silly

gaunt marlin
#

so you want him to do this ?

for row in image_path:
  image_url = site_url + str(row)     image_path_list.append(image_url)

i see no point in setting variable for this simple loop it's better if i put a comment to it

for row in image_path:
   # concat site url and image path
   image_path_list.append(site_url + str(row)  )
vestal hound
#

unless you actually don’t use the value at all

#

yes

gaunt marlin
#

well yeah you don't use the value at all in this logic

vestal hound
#

I would prefer the former

#

although the variable names overall are weird IMO

gaunt marlin
#

i don't set the variable name it's from the person asking

vestal hound
#

like I would imagine a container for image_url would be called...image_urls...?

#

yeah, just a comment

#

IMO where you can express your intention in code or a comment

#

code is always better

#

as far as possible one should strive to write code that does not need comments

gaunt marlin
#

it's opinions based, i see comment are more useful because python don't have to execute it(maybe my term is wrong because english is not my main language but you get what i mean)

vestal hound
#

binding to variables has almost no cost

gaunt marlin
#

comment are for the people that will develop on your code later in the future, even how simple your code is, having a comment always better for them to understand

#

or even for yourself in the future when you come back to the project

vestal hound
#

comment are for the people that will develop on your code later in the future, even how simple your code is, having a comment always better for them to understand
@gaunt marlin not always. adding comments where they are unneccessary adds noise.

gaunt marlin
#

yeah i don't mean comment on every line, just on some logics

vestal hound
#

and

#

there are only two possibilities.

#

either your code can be understood just by looking at it, or it cannot.

#

in the second case, you could use a comment

#

but you should also think about whether there is a way to write it such that it is clearer

gaunt marlin
#

if i remember correctly assign variable mean you binding name to an object in python. I usually work in C so pointer i'm familiar with

vestal hound
#

if i remember correctly assign variable mean you binding name to an object in python. I usually work in C so pointer i'm familiar with
@gaunt marlin basically, there's a dict-like structure that has to be updated.

#

but like I said, the cost is so small that it is basically negligible.

#

sounds like a micro-optimisation to me

gaunt marlin
#

yep

#

unless it's used i don't consider setting variable for it

#

not for something simple as a loop to append list

vestal hound
#

honestly, in this case

#

I would prefer neither approach

#

and go with image_path_list = [f'{site_url}{row}' for row in image_path]

#

hm.

#

actually, no

#

yeah, that.

gaunt marlin
#

yeah it can be easy as a list comprehension, but i know the person asking probably a newbie so i just post simple structure of it

merry copper
#

you got it right

vestal hound
#

the point is the f-string

#

as opposed to string concatenation

#

but well

#

I mean it's a relatively minor thing overall

gaunt marlin
#

point taken

vestal hound
#

and I feel like for a beginner

#

more steps might be clearer?

#

but yeah it's a code style question IMO

#

I'm personally super against comments

merry copper
#

as a newbie, comments are what help me get through the lines of code

vestal hound
#

because I think that if I need to write a comment I probz did something wrong

#

so I should refactor first

#

which is not something everyone agrees with

#

I think docstrings and architecture documentation >>>>> comments

gaunt marlin
#

i worked in large project usually many people need to read other person code which write in the programming language they don't understand(maybe to implement the logic for their similar project). We always write comment for those purpose, i once need to implement another old codebase(from programmer who left the company) who wrote in typescript(which i haven't learn) to implement for python. So you can understand where it come in handy

vestal hound
#

yup, I too have worked with other people on professional projects.

#

and IME

#

everything that was a comment

#

should have been one of these three:

  1. better code
  2. a docstring
  3. external technical documentation
#

especially docstrings

gaunt marlin
#

technical documentation is like a dream to have(once in a bluemoon on some project), but you understand it hard to come by where an old project has it

vestal hound
#

yup

#

so I guess what I'm asking is

#

in the ideal case...would you want comments or proper documentation?

#

I'm not saying comments are bad

#

I'm saying that they are rarely the best solution

gaunt marlin
#

i agree with you but i see that it's more important to use comment(not everyline, only on some difficult logic), as you see also in open sources people tend to leave comment on

plucky tapir
#

Django: if a user is inputting their daily budgeting info, should it be updating the database or creating a new post each time? For instance, expense name, cost, and date

gaunt marlin
#

@plucky tapir you meanupdating existing data of user daily budget(1 record) or create new record for each daily budget info. , right?

plucky tapir
#

@o0o0keem#9279 that is right

gaunt marlin
#

based on your frontend design, do you show old budget info records? if you only show 1 then i would go with the updating existing data instead of creating one

vestal hound
#

Django: if a user is inputting their daily budgeting info, should it be updating the database or creating a new post each time? For instance, expense name, cost, and date
@plucky tapir so you have a correspondence between expenses and rows

plucky tapir
#

@gaunt marlin
Ah I see. I will try to make a weekly graph or chart eventually
so probably new record right?

gaunt marlin
#

yep if weekly graph then you need to save those

gentle ingot
#

Thanks @gaunt marlin

kindred bay
#

Using Django. Trying to make a family tree app, I have foreign keys for mother and father in my "person" class and it's working, but I'm trying to figure out how to get a child field to populate. So if any child lists a parent that parent automatically has that child listed as a child.

glass blaze
#

guys, any good Design Pattern book for django?

vestal hound
#

Using Django. Trying to make a family tree app, I have foreign keys for mother and father in my "person" class and it's working, but I'm trying to figure out how to get a child field to populate. So if any child lists a parent that parent automatically has that child listed as a child.
@kindred bay show models

clear arch
#

I am having trouble learning django any tips would be helpful

unborn dust
#

Hello, I am trying to load fixtures with OneToOneField data in it, and they seem to fail no matter how I try to dump my data
Is there a way for me to load this data into my database
the error I keep stumbling upon is User(2121) = pk DoesNotExist
with 2121 being replaced by a different value every time

vestal hound
#

@unborn dust what do you mean "fixtures"

unborn dust
#

the thing I get in json format after doing dumpdata

vestal hound
#

oh wow

#

I never knew Django had that functionality

#

TIL

unborn dust
#

lol

vestal hound
#

wait so you're saying you dumped data and then tried to load it and it didn't work?

unborn dust
#

yea mainly because of the stupid one to one field

#

let me show my models

#
class CollegeAdmin(models.Model):
    user = models.OneToOneField(User, primary_key=True)
    college = models.OneToOneField(CollegeModel, related_name='user')
    verified = models.BooleanField(default=False, db_index=True)
    active = models.BooleanField(default=True, db_index=True)
vestal hound
#

hm

#

what's your Django version?

unborn dust
#

1.11 sadly

vestal hound
#

do you have any signals?

#

1.11 sadly
@unborn dust this might be the problem

#

that's REALLY old

unborn dust
#

i mean it's an old project

vestal hound
#

and I found some issue reports

#

about this

unborn dust
#

yeah

vestal hound
#

for older versions

#

meh

unborn dust
vestal hound
#

yeah, that

#

could just be a bug in that version

unborn dust
native tide
#

gm are you senior? 😳

clear arch
#

return render(requests, 'index.html', {'name1': name1, 'name2': name2, 'name3': name3}) how to make this better?

#

I don't just wanna keep doing {'name1': name1, 'name2': name2, 'name3': name3... so on}

gaunt marlin
#

@clear arch how many name you want to generate ? is there a limit ?

clear arch
#

there are 3 names for now

#

but if I want like alot of name I don't want to type same thing twice

unborn dust
#

why not just a list instead?

#

{"names": ["james", "jessie", "rock", "chad"]}

clear arch
#

so you mean

names = [name1, name2, name3]
return render(requests, 'index.html', {'names': names})```
#

will this work?

unborn dust
#

yea

clear arch
#

ok

#

thx

gaunt marlin
#

yes that how it should be, in a list so you can just loop through it on template

clear arch
#

{% for _ in _ %} and {% endfor %} right

haughty turtle
#

Prod = Product.objects.filter(category==i)

#

Correct way to filter by match

#

and can I access a QuerySet from html passed into views, say I pass in 20 objects of Products, then in my html can I access product_names from Products

#

Got my first question answered

gaunt marlin
#

@haughty turtle it's = not ==

haughty turtle
#

yeaup got that one @gaunt marlin Do you know about my second answer

haughty turtle
#
         <div class="product_categories">    
            {% for i in context %}
                <div class="product_category" id=i>
                    {% for p in context[i] %}
                       <div class="product_name" id=p.product_name>
                           <span class="product_price" id=p.product_price></span>
                           <span class="product_description" id=p.product_description></span>
                           <span class="product_photo" id=p.product_photo></span>
                           <span class="product_gener" id=p.gender></span>
                       </div>
                    {% endfor %}
                </div>
            {% endfor %}
        </div>```
#

is this correct

#

in the way I am grabbing my items from the QuerySet and putting id name as so from my QuerySet

vestal hound
#

gm are you senior? 😳
@native tide am I what?

vapid acorn
#

@haughty turtle I think this way of assigning id's or class names to html objects is vurnerable

#

Because that part aint handled by django

haughty turtle
#

I have to put them inside of double curly brackets right @vapid acorn

vapid acorn
#

yeah

bleak bobcat
#

Also, {% for p in context[i] %} what is that ? What is context here ?

haughty turtle
#

Yeah I just got an error in that just now was going to comment on it

#

so context is a dict from my views

#
def index(request):
    context = {}
    categories = Category.objects.all()
    for i in categories:
        Prod = Product.objects.filter(category=i)
        context[i] = Prod  
    return render(request, 'product/index.html', context)```
#

Could not parse the remainder: '[i]' from 'context[i]'

vapid acorn
#

but context should be like {"name":name_var}
and in code you can just access name

#

I wrote that before I saw your code

#

So just pass in a list as products, then loop through products and access them like product.name ...

bleak bobcat
#

tbh I don't really understand your code

vapid acorn
#

me neither

haughty turtle
#

I cant store QuerySets in dicts then @vapid acorn

frail hornet
#

Hey!
I was working on one woocommerce website but after almost completing the project my client bailed out. I want to sell that project because I'm in need of money. If any one is interested please dm me. Prices negotiable.

bleak bobcat
#

Get a contract next time 👀

vapid acorn
#

yeah haha

haughty turtle
#

@vapid acorn can I not store QuerySets in dicts? are they not the same as sets or not

bleak bobcat
#

What do you mean ? A dict can store anything

haughty turtle
#

So why do I need to store a list then. I am storing querysets in my dicts so what is my error about then

vapid acorn
#

you dont need to, I think It would be simpler tho

haughty turtle
#

Why am i getting Could not parse the remainder: '[i]' from 'context[i]'

stable kite
#

@haughty turtle show your Category model

bleak bobcat
#

You're doing 1 query to get all categories, then for each of them you're doing another query to get its products, and then you store that in a weird way. Why not just get all the products from the start ?

haughty turtle
#

`class Category(models.Model):
category_name = models.CharField(max_length=100)

def __str__(self):
    return self.category_name`
native tide
#

anyone good at js/jquery here?

stable kite
#

@haughty turtle try thispy def index(request): context = {} categories = Category.objects.all() for i in categories: Prod = Product.objects.filter(category=i) context[i.category_name] = Prod return render(request, 'product/index.html', context)

bleak bobcat
#

That's still making an additional database query for every single category....Just...why

#

If you have 1k categories those 3 lines make 1001 database queries

haughty turtle
#

at least tell me the filter name that you are speaking about @bleak bobcat

bleak bobcat
#

There's no need to filter anything

#

context = {"products": Product.objects.all()}
Then use the templatetag I linked earlier

haughty turtle
#

You just sent me to a documentation about filters, you obviously know something I dont why not just say it then, I am using what I have learnt from python

#

That has like 500+ built in functions I am looking through

bleak bobcat
#

Have you read what I sent ? It points to a specific filter on that page

haughty turtle
#

I am still reading, it never pointed me to a specific filter @bleak bobcat

#

Like 500+ Functions I have to read through

bleak bobcat
#

It should point to the regroup one, that's what the #regroup at the end of the url is for

haughty turtle
#

didnt have one when I clicked on it

#

Ah cause I was clicking on the big blue link @bleak bobcat

#

it cuts that part off

#

reading regroup it seems like it would be more work.

#

I have to sort my products into a list or dict

devout coral
#

You are just trying to organize your items by category no?

bleak bobcat
#

I give up

devout coral
#

I don’t understand why the code I had given you won’t work? (With some modifications for your specific model)

haughty turtle
#

It does and mine does also @devout coral

devout coral
#

So what’s the issue

haughty turtle
#

@bleak bobcat is suggesting that I use regroup, trying to see the benefit, it was suggested to me I am looking into it and just seeing the pros and cons

devout coral
#

Yeah... pre optimization normally leads to no benefits and a total waste of time and maybe more confusing code. I say take what you have and move on. There is one loop and one query to the database not terrible.

haughty turtle
#

Ah ok got it now so your code does seem better optimized, it's only one line in my views.

context = {"products": Product.objects.all()}

{% regroup context by Product.category as category_list %}

#

But then I am still looping through the next list @bleak bobcat , does objects.all not only make one query call?

#

Providing me a list of all the categories, why would it make 3 calls?

#

I would still be making calls to the object in regroup, as I would with the ones in my list.

#

It's like saying if I have 5million products is object all going to make 5million query calls? That would be a bit silly as I thought it is providing me a list only one time ?

devout coral
#

Anyone here know if there is a best practice on how to handle permissions for users?

merry copper
#

Does anyone here know how to show image in FastAPI?

vapid acorn
#

@devout coral If you are using django you can use the build in user model and if you need more than staff, superuser and normal user you can add more manually by modifying the model.
in -for example- your html you could do {% if request.user.is_staff%}<p>Hello mr staff </p> {% endif%}

devout coral
#

@vapid acorn That is not what I am talking about. I am talking about the permissions for the user model.

vapid acorn
#

to access and modify the user db or what?

devout coral
#

Not sure if there was a better way.

#

Do you know of the @permission_required decorator?

vapid acorn
#

Oh sorry I really missunderstood your question at first

#

no sorry, haven't used that yet

devout coral
#

It is not that this system is not working, I just want to know how other people do this and if there was a better way.

vapid acorn
#

yeah, but I think I can't help you with that sorry

devout coral
#

No worries.

haughty turtle
#
class Product(models.Model):
    product_name = models.CharField(max_length=100)
    product_price = models.DecimalField(max_digits=5, decimal_places=2)
    category = models.ForeignKey(Category, on_delete=models.CASCADE)
    gender = models.ForeignKey(Gender, on_delete=models.CASCADE)
    product_description = models.CharField(max_length=250)
    product_photo = models.ImageField(upload_to='product')
    
    def __str__(self):
        return self.product_name``` @stable kite I got `Field 'id' expected a number but got 'Clothing'.` it seems that I got my category name correctly but category inside of my product model is represented as a number not a string
#

nvm

#

Was passing in the category name instead of the object itself

stable kite
#

ok

haughty turtle
#
Prod    
<QuerySet []>
categories    
<QuerySet [<Category: Clothing>, <Category: Accesories>, <Category: Textiles>]>
context    
{'Accesories': <QuerySet []>,
 'Clothing': <QuerySet [<Product: Test 1>]>,
 'Textiles': <QuerySet []>}
i    
<Category: Textiles>
request    
<WSGIRequest: GET '/'>``` but then this is my local variable, I am still getting `Could not parse the remainder: '[i]' from 'context[i]'` on `{% for p in context[i] %}` in my html code
#

I mean I try placing error handing with if statements it did nothing

#

@stable kite am I accesing the index in my dict incorrectly

stable kite
#

@haughty turtle where did you this error?

#

@stable kite am I accesing the index in my dict incorrectly
@haughty turtle you can't access dictionary by index you have to use keys

haughty turtle
#

thats what I meant had to rush out to do something, @stable kite but I am placing my keys and I do not know its not grabbing it it seems like

#
        <div class="product_categories">    
            {% for i in context %}
                <div class="product_category" id={{i}}>
                    {% for p in context[i] %}
                        {% if len(context[i]) != 0 %}
                           <div class="product_name" id={{p.product_name}}>
                               <span class="product_price" id={{p.product_price}}></span>
                               <span class="product_description" id={{p.product_description}}></span>
                               <span class="product_photo" id={{p.product_photo}}></span>
                               <span class="product_gener" id={{p.gender}}></span>
                           </div>
                        {% endif %}
                    {% endfor %}
                </div>
            {% endfor %}
        </div>```
#

I know I have two keys that are empty, so I have this if statement but still nothing

stable kite
#

@haughty turtle you keys are string not ints

bright spindle
#

is there anyone here experienced with caddy, caddycaddycaddy

haughty turtle
#

ah

#

nvm

#

Nvm, blah my mind is all over the place, all this arguing with my wife... yes my keys are strings @stable kite are they not supposed to be

#
{'Accesories': <QuerySet []>,
 'Clothing': <QuerySet [<Product: Test 1>]>,
 'Textiles': <QuerySet []>}``` their stored as string in my dict, which then stores a QuerySet
stable kite
#

but you cant iterate over dictionary

#

in your html

#

they aren't list

haughty turtle
#

but in python I can iterate over dictionaries just fine @stable kite

#

for keys in dict: gives me the names of all my keys, it always has. Whats the difference in using this in Django

stable kite
#

but in python I can iterate over dictionaries just fine @stable kite
@haughty turtle you can but it gives key not values

#

so you need access it like dict[key]

haughty turtle
#

thats what I am doing @stable kite

#

{% for i in context %} <div class="product_category" id={{i}}> {% for p in context[i] %}

#

It grabs my keys in the first for loop and my error is in my second for loop

#

context[i] should give me my QuerySet and I am supposed to be looping through it

native tide
#

Is this HTML language ?

#

It's harder than Python

warm igloo
#

that is templating code, Jinja for instance @native tide

native tide
#

👍

warm igloo
#

@haughty turtle Have you run a debugger and a breakpoint on those loops? You may not be getting what you think you should be getting.

haughty turtle
#

Where would I run the debugger? If the code is basically in my browser ? @warm igloo

stable kite
#

@haughty turtle got your mistakes

#

change your render code

haughty turtle
#

What's wrong with it?

stable kite
#

post your code

#

i will tell you

#

@haughty turtle try this

    context = {}
    categories = Category.objects.all()
    for i in categories:
        Prod = Product.objects.filter(category=i)
        context[i.category_name] = Prod  
    return render(request, 'product/index.html', {"context":context})```
haughty turtle
#

You think so? @stable kite

from django.shortcuts import render

from .models import Question


def index(request):
    latest_question_list = Question.objects.order_by('-pub_date')[:5]
    context = {'latest_question_list': latest_question_list}
    return render(request, 'polls/index.html', context)``` In the django tuts they just pass the dict name in directly
vale vault
#

Does anyone use flask?

#

I could use some pointers to proper design patterns. Especially involving initializing the database.

devout coral
#

@haughty turtle What is your issue?

swift sky
#

not sure if this is the right place to ask, but what's the ebst way to return an sql query into an xls download file

haughty turtle
#

Trying to access a value in my dict by inputting a dictionary key, not working