#web-development
2 messages · Page 106 of 1
scalability reasons, with a million users at a time storing all those cookies builds up
whether that really matters.... 
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
@native tide so you are saying you would store session data inside your jwt?
ive never actually used session cookies, what exactly are you trying to get at by 'session data'?
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
if you used create-react-app it should autorefresh you or at least it does for me 
you are running with npm start ye?
yeah for me it autorefreshes too but im on pycharm
Can someone help me out with templates?
vscode for me and it autorefresh. it shouldnt matter what ide 
Need Help in Flask Mongoengine
@clear arch whats the question
I made all the script src, href, img src, src static but it still doesn't work
I also did {% load static %}
send the code
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.
Set your static directory in settings.py STATIC_URL = '/static/' and store all of your static files in a static/ directory
STATICFILES_DIR and STATIC_ROOT did that
and static_url?
what directory are your static files held in
I have a project folder and in that I have static folder
hmm I dont know what else you can check...
want the error?
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'
See those line numbers I made them all static still error is there
It says Not Found in all of them
omg
@native tide I typed STATIC_DIR and forgot S omg
this debug oof
ok
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
Hi
there is no Manage.py file in my django directory
I have searched everywhere
hello?
Hey guys web dev noob here
what exactly is the difference between an API, Framework, and Library
im so confused
a Framework creates websites
web framework like Django or Flask
a Library is something you import
example: ```
import random
from time import sleep
yeah but you can interact with external databases and servers with APIs as well as libraries so whats the diff?
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
what about selenium?
that automates stuff
isnt that similar to Plex API?
I dont think so
Plex API connects to plex only and finds info from plex only
Selenium automates web stuff
like button pressing
what about the requests library?
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 just make a new project then copy the manage.py
You will need to change the project name but that is all
make a new Pycharm project
Yes
@devout coral
@summer wyvern You get this figured out?
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
do I have to install django in the other project
there is no manage.py @devout coral
@summer wyvern How did you startproject without the django library installed?
I have installed Django again
ok?
'startproject' is not recognized as an internal or external command,
operable program or batch file.
I tried in both projects
That is not the full command to start a project. Is this your first django project?
Let me suggest you read this.
https://docs.djangoproject.com/en/3.1/intro/tutorial01/
I have been following a tutorial
buildwithpython Django Tutorial
he showed how to install
start a venv
and start the server
with manage.py runserver
Did it not show him setting up his project?
he started a new project
he never ran a django-admin command?
Must be a bad tutorial. Would you llike me to show you a good tutorial to follow?
its a very good tutorial. I was reccomended by many people
Apparently not... You got lost in the first few minutes..
That is django 2.1 ....
So why are you learning from something out dated?
is it changed now
Django had a MAJOR change.
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
In this Python Django Tutorial, we will be learning how to get started using the Django framework. We will install the necessary packages and get a basic application running in our browser. Let's get started...
The code for this series can be found at:
https://github.com/Core...
@summer wyvern Use that tutorial
It is really good and even goes into deployment
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
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 %}
would work, thank you, but I think the solution I found on the internet is a bit more elegant
hey guys who learnt django / flask, did you actually get a job from it?
@native tide yup
@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 😄
do u have projects done ?
I started doing free projects for my uni, and then they hired me
yeah, soon I will have one project done with Django backend + React fronten
That's cool
oh nice
then yea find a company that are looking for developers, and show them ur work
Ok, sounds good. I'm going into university next year so I have some time to work on it 😄
yup good luck!
Thank you 🙂
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?)
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
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
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)
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)
@vapid acorn have you tried using redirect method?
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
Guys when do we use django rest framework??
@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 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
@sterile peak Yes but are you trying to make a website? Usually api's do not have a front end.
@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
@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).
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
@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?
@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.
@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
@hazy night Sure
@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 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.
@devout coral yes that's what I feel too! Did you take a look at his code
Not yet
alright man, if you find it interesting please let me know too.
so if this is a python server and this is the web-dev section then is there we talk about web django?
Currently I am working on accessing IBM Lotus notes using Python so I think it might be helpful
@honest rock Among other things
ok? @devout coral
@honest rock ?
About?
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..
@snow sierra You do not delete migrations unless you are deleting the database
@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)
hi
@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
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
@sterile peak Consider lighter framework for pure Rest API like Flask/FastAPI
@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.
Because you deleted your migrations... you would need to delete your database then re run the migrations.
@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
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
@vapid acorn Says it cannot be reached
A timeout or any other error message?
it works
ok
where it is hosted?
I use django and just do runserver 0.0.0.0:8010 with portwarding
nice :)))
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
yeah, the domain isnt beautiful tho (blabla.hopto.org) but who cares
no one 😄
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
@vapid acorn Oh it is being blocked in my network
maybe because it is http not https
or just because it isnt in like a google index or sth
tor it @vapid acorn
what do you mean?
oops.. wrong chat
oh ok lol
Yeah because it is not indexed.
oh ok thanks
Is there a way to import bootstrap into a custom css file?
how do i serve a single static file in caddy for a directory like url/path/
theres barely any guides online
@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 🤦♂️
@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
Uhh what?
!important! will always first and important for your css
"!important override the cascade?"
lol, little bich bot
im pretty sure i learned this but it was so long ago and i never used it
Yes, it seems that is what he wants to do. Override what the primary-btn color is
Yeah but that would require to download bootstrap locally change it then compile it
also you can in html without any imports... <button style="color: white;")</button>
He is clearly using the cdn...
So why have him go through the trouble of downloading it changing it, compiling it etc.
i mean its up too him
but if i was building production code its not what I would go with
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.
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
CS50 will not expect you to download the boostrap scss. I suggest to go with the easier approach and include a !important
Figured out why it wasn't working. My a tag was changing the color not the button
@gentle ingot You have a button wrapped in an <a> ?
I have the text wrapped in <a>
<button type="button" class="btn btn-primary"><a href="images.html">Image Search</a></button>
Why are you doing that exactly? For the button appearance?
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)
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
YW
Is this pure html, css right now? Or are you building this with a backend?
Just curious
Pure html and css
Is it a good idea to list supported file upload types on a web site? Or is that divulging too much information?
Project 0 included python but like. Its an overview and not useful within context of the course
@trim star Why not include it? I would say include it.
@gentle ingot Well good luck
@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
it has many ways.
@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?
example:
def validate_file_extension(value):
if not value.name.endswith('.pdf'):
raise ValidationError(u'Error message')
@snow sierra Thats worse than checking the content type right? Someone could just change the file extension
from FORM?
@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.
did you use Django forms or HTML?
@snow sierra they are using django forms
These are some of the things I am talking about: https://owasp.org/www-community/vulnerabilities/Unrestricted_File_Upload
i could have sworn to god django automatically checks files not just extension?
Sorry for the ping misread the comment.
@native tide I thought that too
@native tide Nope it only checks the extension
¯_(ツ)_/¯
Let me double check
hey guys, does anyone know how i should deserialize with marshmallow, a database model that in one of its fields contains another database model?
Django is a really secure framework. These packages make it more so or help you maintain Django's high level of protection.
There is a FileExtensionValidator but they specifically tell people not to rely on it as someone could just change the file extension
Also someone needs to build a better CAPTCHA library with images not just fucking text
because right now, it's only deserializing the "root" object, and the nested objects don't get unpacked
Yeah.
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...
I mean if someone uploads a shell script but the file extension is .pdf what are they gonna do with that?
*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
How will they execute it though if it has a .pdf extension?
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
Can I ask what u do snowball?
Yes, but its still an issue in my opinion even though there would need to be another vulnerability present
U can easily implement ur own method for doing it
all ud have to do is check the header wouldnt u?
@native tide Sure... I am a month away from being the IT Manager at the company I work for.
@devout coral there could be a case where other vulnerabilities are present that can change file names/execute files
Thanks bro, self taught got me the job. But I went back to school and I finish next fall (IT).
it is very low level trick... i think django form default can handle like this tryies
Django seems pretty robust from what i've seen
@trim star But then those are other vulnerabilities... I do not think you should worry too much about this tbh
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
and for the most part i think u need to try to make it insecure "excluding js"
@native tide May I ask what you do?...
I mean actually u only need maybe 5 lines of code.
Nothing lol
I study everyday
thats it
i dont even go to college anymore
dropped out
Teaching yourself?
@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
I find they teach garbage at school
Nice, May I ask your age??
I'm 20
Nice
@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
What sort of experience in web development do you have?
I think he said he already is checking that
@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.
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
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.
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)
Most likely just in the wrong directory/pointing to the wrong file.
@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
I think it would be good for micro services
Like if you need to build a separate site for payments.
i need help with a package called django-spirit ;-;
and then redirect too it.
@native tide I think flask is the king of microservices tbh
flask is a mother of python web :d d
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
The overhead for it is small compared to django. Once you add all the functionality that django has though the performance difference is negligible.
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
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
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 incorrect path (my first opinion)
@snow sierra no I checked
no libs
it's correct path
it's correct path
@mortal mango screenshot it
this is why u use docker 😂
@native tide IDK, maybe a 1-2 full workweeks not including deployment.
and what OS do you using?
minium viable product.
Hahaha my front end skills are like uhhh.... not great
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
@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.
@native tide How bootstrappy does this look?
that looks pretty good tho
Thanks
@native tide How bootstrappy does this look?
@devout coral does those EXPORT icons works?
or what is it
i think it looks fine lol
@snow sierra What do you mean if they work? Like function on the website?
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
@native tide It will be an internal tool
@snow sierra What do you mean if they work? Like function on the website?
@devout coral Left side of 'Total Ppints'
as long as it doesnt look like trash
@snow sierra Yes everything functions
and what it do?? Print Version? pdf? excell
@snow sierra They export pdfs, there are titles for everything.
This is my current to do list before launching v1
@native tide Yes, why?
Was just wondering ahaha
I feel like front-end is an art sorta thing
u really gotta use it to learn it
These?
yeah
I am
i gotta be rip
luckly if u put enough time into anything ital turn out good
even if ur complete trash
I wish I had screenshots of my earlier account page so you could see the difference
pure bootstrap?
This site is bootstrap plus my custom css
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
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.
can you guys tell me i18n alternative methods ??
@snow sierra i18n?
@devout coral one more Languages for website..
@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 Like a screenshot of all my routes?
i don;t want something bad for you and for your code lol :d
yes
👍 👍 👍 👍 👍 👍 👍 👍 👍 👍 👍 👍
What do you mean?
i never used include(file) in path() .. 1 more step in my mind
That the urls.py for the project (the one with all the includes) should be in the same directory as settings.py?
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.
@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
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
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
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
nodemonworking 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 ??
@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.
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
Sorry bud, I have no clue how to help you.
@devout coral
lol like i said before
there is no problem with it looking like bootstrap
Customers dont know
unless ur a web dev...
Yeah I know, but the first design just looked bad.
cause of bootstrap?
ooo
yeah it looks dreadful
how much did u change css wise?
i think the main difference is more layout
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.
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
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
Have u ever considered maybe just reading some books on algos and software deisgn
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.
Well I have a long term plan. I want to have my PhD in CS to teach college level for “retirement”
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
Yeah, I do not think people really do that
Do what?
Follow it rigidly. And by people I mean some software companies
google did it lol
Well damn
But for most thinks I think they take from it and adapt it to their project
but theres a rule that code should be open to extension but closed to modification
You live in the US?
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
Ok cool
I would hate doing front end without bootstrap
@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
¯_(ツ)_/¯
@native tide that’s cool
I’d like to make a multiplayer game but I am really focused on this current project.
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...
Hello, anyone pretty good with Flask?
@viral slate Well it's the web-dev channel so I'd hope so
I'm sure there are a lot of people in this world who are pretty good with Flask yea
lol awesome, I'm going to try to start a Flask project and I was looking for someone for pointers
what's the question
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...
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.
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.
@viral slate I'm confused
are you asking about combining the data or about how to build a backend/frontend using it?
Yeah, right now I'm working on the backend.
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.
On mobile right now but what does this return.
categories = Category.objects.all()
A list?
A queryset
A queryset or set? I mean I could convert it to a normal set or list right?
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
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?
You can loop through it as you would a list, don't convert it unless you have a very specific reason to
Ok cool thanks
Ok cool thanks
@haughty turtle what do you want to do with it?
there may be a more efficient way
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)?
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
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?
I just want to grab each item in the list to use for another var.
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
For items in Category:
Product.objects.filter(category__startswith=items)
On mobile can't indent correctly
@vestal hound
@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?
didn't all your homies love flask a few weeks ago?
you should tell your homies about Bottle too
why the change from flask to django?
Ive only heard of django and flask. I'm looking into flask more since I've heard the learning curve was lower.
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.
@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 I’m pretty sure you can do all that with one query and one loop. One sec.
does anyone know a good resource for using Marshmallow library? the docs kinda suck
@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)
@native tide so do you think I should start learning by using Django?
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
yeah all his homies love django
facts bro
homies backing django on foenem fosho fosho
react gang too wya
all my homies hate setState()
@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.
SLoC increases then, is there a benefit to using that concept over the one I have?
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
@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?
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?
I'm going for something like this
okay
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
I don't beleive realtime is required.
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
okay, so what's your mechanism for updating the DataFrame in memory
That I'm unsure of. Right now I'm basically at scratch.
why don't you want to use a database actually
I think I'll have to and set it up locally to start my project.
I'm going for the best method possible
yeah.
you'd need to learn some SQL, most likely, though
or do you already know it?
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.
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
does this make sense ?
@gaunt marlin yes! Thank you so much!
@vestal hound thank you for trying to help me. I appreciate it
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 withrequest.pathto 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
@gaunt marlin it's not working.
@merry copper what not working? does it return error ? what is the result ?
!code
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.
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
@merry copper try:
image_path_list.append(site_url + str(row))
instead
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?
@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}
@merry copper try:
image_path_list.append(site_url + str(row))instead
@gaunt marlin it works!
Thank you!
@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
Make the code clear and understandable
@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
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
I can make my django project a rest api to use the data to make charts from javascript?
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
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) )
well yeah you don't use the value at all in this logic
i don't set the variable name it's from the person asking
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
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)
binding to variables has almost no cost
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
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.
yeah i don't mean comment on every line, just on some logics
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
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
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 adict-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
yep
unless it's used i don't consider setting variable for it
not for something simple as a loop to append list
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.
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
you got it right
the point is the f-string
as opposed to string concatenation
but well
I mean it's a relatively minor thing overall
point taken
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
as a newbie, comments are what help me get through the lines of code
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
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
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:
- better code
- a docstring
- external technical documentation
especially docstrings
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
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
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
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 you meanupdating existing data of user daily budget(1 record) or create new record for each daily budget info. , right?
@o0o0keem#9279 that is right
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
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
@gaunt marlin
Ah I see. I will try to make a weekly graph or chart eventually
so probably new record right?
yep if weekly graph then you need to save those
Thanks @gaunt marlin
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.
guys, any good Design Pattern book for django?
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
I am having trouble learning django any tips would be helpful
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
@unborn dust what do you mean "fixtures"
lol
wait so you're saying you dumped data and then tried to load it and it didn't work?
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)
1.11 sadly
do you have any signals?
1.11 sadly
@unborn dust this might be the problem
that's REALLY old
i mean it's an old project
yeah
and I found this answer too but idk how to use this https://stackoverflow.com/questions/18521796/django-fixtures-and-onetoonefield
gm are you senior? 😳
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}
@clear arch how many name you want to generate ? is there a limit ?
there are 3 names for now
but if I want like alot of name I don't want to type same thing twice
so you mean
names = [name1, name2, name3]
return render(requests, 'index.html', {'names': names})```
will this work?
yea
yes that how it should be, in a list so you can just loop through it on template
{% for _ in _ %} and {% endfor %} right
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
@haughty turtle it's = not ==
yeaup got that one @gaunt marlin Do you know about my second answer
<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
gm are you senior? 😳
@native tide am I what?
@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
I have to put them inside of double curly brackets right @vapid acorn
yeah
Also, {% for p in context[i] %} what is that ? What is context here ?
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]'
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 ...
tbh I don't really understand your code
me neither
I cant store QuerySets in dicts then @vapid acorn
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.
Get a contract next time 👀
yeah haha
@vapid acorn can I not store QuerySets in dicts? are they not the same as sets or not
What do you mean ? A dict can store anything
So why do I need to store a list then. I am storing querysets in my dicts so what is my error about then
you dont need to, I think It would be simpler tho
Why am i getting Could not parse the remainder: '[i]' from 'context[i]'
@haughty turtle show your Category model
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 ?
If you need to group the products by categories when rendering them you can use https://docs.djangoproject.com/en/3.0/ref/templates/builtins/#regroup
`class Category(models.Model):
category_name = models.CharField(max_length=100)
def __str__(self):
return self.category_name`
anyone good at js/jquery here?
@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)
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
at least tell me the filter name that you are speaking about @bleak bobcat
There's no need to filter anything
context = {"products": Product.objects.all()}
Then use the templatetag I linked earlier
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
Have you read what I sent ? It points to a specific filter on that page
I am still reading, it never pointed me to a specific filter @bleak bobcat
Like 500+ Functions I have to read through
It should point to the regroup one, that's what the #regroup at the end of the url is for
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
You are just trying to organize your items by category no?
I give up
I don’t understand why the code I had given you won’t work? (With some modifications for your specific model)
It does and mine does also @devout coral
So what’s the issue
@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
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.
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 ?
Anyone here know if there is a best practice on how to handle permissions for users?
Does anyone here know how to show image in FastAPI?
@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%}
@vapid acorn That is not what I am talking about. I am talking about the permissions for the user model.
This is what I have and there are more.
to access and modify the user db or what?
Not sure if there was a better way.
Do you know of the @permission_required decorator?
Oh sorry I really missunderstood your question at first
no sorry, haven't used that yet
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.
yeah, but I think I can't help you with that sorry
No worries.
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
ok
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
@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
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
@haughty turtle you keys are string not ints
is there anyone here experienced with caddy, caddycaddycaddy
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
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
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]
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
that is templating code, Jinja for instance @native tide
👍
@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.
Where would I run the debugger? If the code is basically in my browser ? @warm igloo
What's wrong with it?
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})```
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
Does anyone use flask?
I could use some pointers to proper design patterns. Especially involving initializing the database.
@haughty turtle What is your issue?
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
Trying to access a value in my dict by inputting a dictionary key, not working