#web-development
2 messages · Page 134 of 1
So many ads that it can bring a AMD Eypc 128core CPU to its knees
pls I haven’t coded in a while that I basically forgot most of python
just doing hackerrank
@native tide so what did you ping me for? do u have an answer to my question?
@hybrid bobcat no just your profile pic
@hybrid bobcat ask @glossy arrow
Hm?
Aboo may have an answer to your issue. They're our local Flasker
@glossy arrow this is his question
Lmao, I'm not amazing with flask, mostly just adequate
Wait for your issue wouldn't you want to remove the <path: part?
@hybrid bobcat I assume
I'm a bottle guy
why?
But if its like bottle remove the <path part
Most micro frameworks work the same
i dont know the path, theres a lot more static files in the folder
So your code can't locate your static files?
@app.route('/static/css/<filename>')
def static_files_css(filename):
return send_from_directory('static', filename=filename)```
Try this
filename can be an absolute path + filename or filename
no, so like originally, the default flask static file endpoint will be able to let my templates reference them, but like yesterday that works, suddenly it doesnt today
no idea why
i changed nothing
Huh
Maybe set the static files manually?
app = Flask('flaskapp', static_url_path='/static')
i did
TIL
Cool
lol
Lol
I'm not that great with css
I know enough to get by though lol
shoves 80k ads into a page designed to fit on a iPhone screen
Lmao
in this case you might be looking for fixed
@vestal hound why not absolute?
i believe fixed is to ur screen width
I would imagine you want your ads to be visible wherever you scroll
that would be fixed
also sticky is fun to play with owo
@vestal hound I don't get static
so static means it will always flow with the page in an absolute position
why don't you google it
I'm sure google will show up an article that will display what you want to know 40% more detailed
oh
Well
@toxic flame
so
ugh
hm
So the view port is like looking out a car window
and a fixed position is like a tree
the viewport can move and the tree will stay in the same position relatively?
Did I get that right...?
So static would follow the view
is it possible to add multiple of the same object to django's m2m field?
I think django lets you set a custom through model which could have a count field
Hello! I am using Flask to build a web portal to connect to a Discord bot. I am running into a bit of an issue with one specific part. I need the user to be able to enter in a date and time into a form, but the users could be anywhere in the world. I then need to be able to translate that time, which is theoretically set from any timezone in the world, to a UTC timestamp. Anyone know how I might do that?
static is the default
okay so
basically everything in HTML is a rectangle.
by default, those rectangles will appear in the order you define them
left to right, and top to bottom.
so if everything on your page is static, it'll follow that order
however, you can also change the position attribute of individual elements, which will change how they render.
in particular, fixed and absolute take elements out of that flow entirely
and position them on the page according to coordinates that you provide
the difference between fixed and absolute is whether they take reference from the viewport (fixed) or their parent element (absolute).
yes, kind of.
Where’s a good place to get started with django html and css
Also do I require to know is ?
Anyone actually using Fabric2 for Django deployments? Seems like the complexity for the upgrade has everyone using some v1 base fork for Python3 compat.
Why am I getting this https://pastebin.com/v9wCsP0m error in Django when trying to use a model from another app? django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet. I have searched online quite a bit and cannot find any information that helps me. Is it common to have to import models from other apps, or am I using poor design? ```python
from django.db import models
from django.apps import apps
User = apps.get_model('discord_user', 'User')
EnumModel = apps.get_model('registry', 'EnumModel')
Create your models here.
class HairColor(EnumModel):
pass
class EyeColor(EnumModel):
pass
class Race(EnumModel):
abbreviation = models.CharField(null=True, max_length=25)
class Sex(EnumModel):
abbreviation = models.CharField(null=True, max_length=25)
class Character(models.Model):
first_name = models.CharField(max_length=15)
last_name = models.CharField(max_length=15)
height = models.FloatField()
weight = models.IntegerField()
image = models.ImageField(null=True, upload_to="character_images/")
hair_color = models.ForeignKey(HairColor, blank=False, null=True, on_delete=models.SET_NULL)
eye_color = models.ForeignKey(EyeColor, blank=False, null=True, on_delete=models.SET_NULL)
user = models.ForeignKey(User, on_delete=models.CASCADE)
sex = models.ForeignKey(Sex, blank=False, null=True, on_delete=models.SET_NULL)
race = models.ForeignKey(Race, blank=False, null=True, on_delete=models.SET_NULL)
dob = models.DateField()
is_deceased = models.BooleanField(default=False)
def __str__(self):
return f"{self.id}: {self.first_name} {self.last_name}"
``` This is the file that errors on line 4: User = apps.get_model('discord_user', 'User'). The User variable is only used in the "user" field under the Character class user = models.ForeignKey(User, on_delete=models.CASCADE)
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
can you do from discord_user.models import User ?
instead of this apps.get_model thing?
@umbral hatch
I'm not really sure of the structure of your models here
is User a model inside of discord_user?
Yes
And I used that previously but I had some other error I think had something to do with "circular import"
This is User model ```py
from django.db import models
from django.contrib.auth.models import AbstractUser
Create your models here.
TODO: Discord-based user
class User(AbstractUser):
pass
Oh, that would be simpler I guess. Is that what is normally done?
I guess I wouldn't really need to import the models then?
user = models.ForeignKey('discord_user.User', on_delete=models.CASCADE)
I would do it this way to prevent this problem, yes
except for EnumModel, I'll see if I get the same error for that
yep
exact same issue, and I need to import EnumModel to inherit the class
After I used a string in the foreign key
User = apps.get_model('discord_user', 'User', require_ready=False) this "worked" but the documentation states "When require_ready is False, get_model() returns a model class that may not be fully functional (reverse accessors may be missing, for example) until the app registry is fully populated. For this reason, it’s best to leave require_ready to the default value of True whenever possible." If someone knows of a better solution please let me know
I've never used apps.get_model before
so I'm sure there's a way to do it without that
what does your registry.models look like?
maybe you can use the string foreignkeys there as well so that you do not have to import from whatever this models.py file is
@indigo kettle registry.models looks like this ```py
from django.db import models
from django.apps import apps
class EnumModel(models.Model):
name = models.CharField(max_length=40)
def __str__(self):
return self.name
class VehicleColor(EnumModel):
pass
class VehicleMake(EnumModel):
pass
class VehicleType(EnumModel):
pass
class Vehicle(models.Model):
character = models.ForeignKey("Character", on_delete=models.CASCADE)
license_plate = models.CharField(max_length=25)
vehicle_type = models.ForeignKey(VehicleType, null=True, on_delete=models.SET_NULL)
vehicle_make = models.ForeignKey(VehicleMake, null=True, on_delete=models.SET_NULL)
vehicle_color = models.ForeignKey(VehicleColor, null=True, on_delete=models.SET_NULL)
class WeaponType(EnumModel):
pass
class Weapon(models.Model):
character = models.ForeignKey("Character", on_delete=models.CASCADE)
weapon_type = models.ForeignKey(WeaponType, on_delete=models.CASCADE)
class LicenseType(EnumModel):
pass
class LicenseStatus(EnumModel):
pass
class License(models.Model):
character = models.ForeignKey("Character", on_delete=models.CASCADE)
license_type = models.ForeignKey(LicenseType, on_delete=models.CASCADE)
status = models.ForeignKey(LicenseStatus, null=True, on_delete=models.SET_NULL)
``` I switched to using string foreignkeys, and it appears that only works for models defined in the same app. I am getting a lot of errors saying something along the lines of registry.Weapon.character: (fields.E307) The field registry.Weapon.character was declared with a lazy reference to 'registry.character', but app 'registry' doesn't provide model 'character'.
oh wait
I need to specify the app duh. Should be civilian.Character
yep exactly
@indigo kettle That worked, thanks for the help
np
I set up a django project on ubuntu with nginx and uwsgi. The problem is that none of the images are loading. When I go into inspect > console, it says the server responded with 500 when trying to get the images. Does anyone know how to fix this? I tried changing permission to 777 but that didn't work.
How do I use JavaScript with Flask?
just include it in your template
Thinking about it now, I'm not sure if that is pretty standard across the other libs or not
but what if I want it separate
Then serve static files
ok thanks
any way I can create a confirmation message in flask?
I made a delete button and I want to prompt user "Are you sure you want to delete this?"
can anyone help me with spoify API called spotipy?
!paste
hello
Can anyone tell me that how to give user only one option to input the value
like either he uploads the text file or copy paste the text code in the flask page
?
do you guys recommend i learn web developement using python?
or the generic languages
what exactly do you mean? django and flask only lets you write the backend.. you wont get around HTML/javascript either way
Hello i have a problem with my venv in django
all package is installed to
Python packages not installing in virtualenv using pip
When i launch my project he dont use the venv but the AppData\Local\Programs\Python\Python39\Lib
to plain? it just doesnt feel right... just cant put my finger on why
use pipenv instead of venv. pipenv just works a lot better in my opinion
honestly
this kind of looks like it was built in 2005 or something
no offence
well
not all of it
the input part does
also "Creator" isn't aligned
which makes it look weird
or at least it doesn't look aligned
Hi am trying to do pagination in Django using javascript and am pretty done, but now i ve run to a problem. Website is not translating django tag urls. How can i solve this ?
not whole code.
data.map((restaurant) => {
container.append(`
<div class="col-xl-3 col-lg-4 col-md-6 mb-4 restaurant">
<div class="bg-white rounded shadow card card-hover">
<a class="card-link" href="{% url 'restaurant_detail' slug=restaurant.slug %}"> ${restaurant.name}</a>
</div>
</div>`)}
thats what im saying. its not set in stone. its bottom aligned
colour scheme seems a bit off
what?
whole site is that color scheme.
how did you come up with it
im saying it doesnt look quite right. like it works, but not super modern. and the creator is bottom aligned with the username
I perceive it as being misaligned
might be a function of different font size and font weight
shrugs
anyway the main thing is the input
when was the last time you saw an input field with a full black border
on a social media website
i pulled the original scheme of a website scheme builder. then it was to plain so i added the dark redish brown/green because they are complimentary colors to the blue and tan
🥴
well
you do you
it looks a bit odd to me
whole scheme
what font is that
is that Arial
I think you might want to consider a different font
my font choices font-family: Quicksand, Helvetica, sans-serif;
it's giving me 2000s vibes
I suspect
your line-height is too low
incidentally
I feel like the alignment of almost everything is weird
i dont have quicksand so its pulling Helvetica i think not sure
ye that seems like it
I Googled Quicksand and it doesn't really look like what you have there
its a common font, my pc is just really old
@wicked elbow some small things
also...I get the vibe that you are randomly throwing colours around
I can see no discernible pattern
to when you are using which colour
which confuses me, as a user
in the sense of "when to use which colour in the colour scheme"
I hope you will forgive my bluntness
the blue is used in page link bars, the tan is the side bar colors, the green is anything editable, and the dark reddish color is for NSFW posts.
the blue is also used for SFW posts
yes, I can see that
but WHY?
i drew them out of a hat? lmao
like you don't just arbitrarily assign colours
to actions
okay
for example
look on Instagram
and tell me
what you associate black with
the website, not the mobile app
never mind, I'll just tell you
everything black is clickable.
of all these, I think the only one that is reasonable is the last
the rest send mixed signals
okay I suggest
go read some UI/UX articles on colour palette construction and usage
because (correct me if I'm wrong) it REALLY feels like you're just throwing colours around randomly
ya. nothing is set in stone. its my style sheet, and its only like 7 lines to completely change the scheme.
no
it's not about which colours you choose for your scheme
it's about what each colour MEANS
anyone used web2py
okay for example
for my website
everything in the primary colour is an action
100%
and the primary colour is not used for anything else
i got a thumbs up from my web designer friend who works for a firm in NZ.
thats how my site is too. its uniform across the pages.
okay then
if you're fine with it
so am I
just one last thing
"web designer" can mean many things
there's some overlap between frontend dev, UI designer, and UX designer
but each of them do unique things
and all skillsets are necessary to make something good
that's point one
actually, I'm just going to stop at point one because the rest is irrelevant
eh, i just know theres like 10k lines of code to put this whole thing togther. worked on it for about a month now
not perfect, by any means. im wearing to many hats
what generic languages are you thinking?
Js, php
theres a lot more options then that
c# and ruby as well
do you intend to be working with anyone?
and how good of a coder are you?
ye I forgot Ruby
And no by myself
do you know
Actually know or just the minimal basics
i dont know flask, so cant comment, but django to me had a huge learning curve. its like its own language in itself
python wise
I would suggest you stick with Python
if you're still a beginner
might as well leverage your existing ability
and get good @ one language
that
But wouldn’t learning django be more harder in the long run ?
or do a full JS stack
harder than?
...why?
not any different then php or js. a language is a language. each has their own quirks
meh
I don't think so...?
but anyway
that's not something you'll know
until you try
different people have different learning speeds
you can learn flask as well, its not django thats hard, its the syntax you have to use to accomplish things, but again thats true of every language. its still python you just have to do things a certain way
basic django is easy, once you get the hang of it.
Sorry for reposting this
Hi am trying to do pagination in Django using javascript and am pretty done, but now i ve run into a problem. Website is not translating django tag urls. How can i solve this ?
not whole code.
data.map((restaurant) => {
container.append(`
<div class="col-xl-3 col-lg-4 col-md-6 mb-4 restaurant">
<div class="bg-white rounded shadow card card-hover">
<a class="card-link" href="{% url 'restaurant_detail' slug=restaurant.slug %}"> ${restaurant.name}</a>
</div>
</div>`)}
wish i could help, i went with front end pagination. so i could control it better
^
i didnt wanted the pagination with numbers so i ve tried something like this
its pretty much working, but its taking the ulr as string
im still not much help. i do everything through an api. everything is done in json
i was googling like a mad man, but found nothing sadly
does anybody know how to refer a model to more than one type of users
i have normal users and some other special users . I want to refer both this user into one model . so whenever I call normal users django should automatically switch to that users and whenever I call special users django also should do so . with my limitted knowledge I cant use foreign key . Is there any better solution . somebody help plz
what?
I didn't really understand that
you mean like
uh.
why can't you just have a BooleanField or somethign
but how
honestly
I don't really get what you're trying to do
maybe you can give an example
say that model is posts . so whenever a normal user want to post something django post model should refer to the normal user so that he can post posts . or else it should refer to the special users who can post
what do you mean "refer"
just we do the same with foriegn key
if there is no second user could we easily do it with foriegn key no ??
take normal user as may be like teachers and special users as students . just like so .
uh
this doesn't really say much.
what is the difference?
in terms of attributes
actually i am doing a project on social media, the normal users are the people like us . special users are the organisations who registered in this social media
I created a model shared so that both users can access it . so that I dont want to repeat the models in both of this model . All I want to switch according to users .
is there any way to achieve
but why
do you need
2 separate models
?
for "normal" and "special" users
I don't see the point
because both they have different functionalities . like an organisation user have branches . normal users doesnt have those functionalities
branch = another model?
No , like branches of a head organisation . I am just mentioning the differences between those users and the difference in their functionalities
but both of them have some functionalities in common . so i decided to create another app. but all i want to switch between users
uh
I feel like
you don't have a very clear data model
so I would suggest
you work on that first
my point is this
you're talking about
business requirements
but my question is about how those affect your architecture
let me clear it first . A user is simply a facebook type users . but an organisations users are those who can raise their company , invest on other companies . etc .... their functionalities are entirely different . but they have something in common . like both they can create posts . engage in group activities .
so and so ... so all i want to make their common tasks into one seperate app ...
...so what's your data model?
u mean the common database model right ?
no.
in other words, what's your plan for reducing business requirements into code
sorry i dont have a vast knowledge
IMO
you are asking the wrong question
because
you only understand
what you want from a business perspective
but not
how to plan
the data/software architecture appropriately
yah , may be right . I wish I know it all
so I would suggest
doing more research on data modelling
to be better able
to ask the right questions
ok thankyou . but atleast can you explain how to achieve method overloading in django
look into abstract models
could you suggest some good reference .
nope
where should i learn flask microframework of python
Hello i have a problem with my venv in django
all package is installed to
Python packages not installing in virtualenv using pip
When i launch my project he dont use the venv but the AppData\Local\Programs\Python\Python39\Lib
You can see YouTube videos
Now I myself am learning flask but it's not going on good track
Facing a tough time
win
mm
Watch multiple videos and find yourself which suits u best
Like whose language u understand
Etc....
English and tamil
By language I don't mean English and that
I mean which content creators way of explaining suits u
python
Bro u don't know hindi
mm no
You can check corey Schaefer, tech with tim, programming with mosh etc...
Bro I am facing problem with database
Np
So has anyone found a good project to work on
Or does anyone want to work on a communal project
@vestal hound i made the input just for you, the color scheme and font ill work on. still working on where to put the reply at, i dont like where they are either
Are you using websockets owo
who?
I have a django project that's running on an nginx webserver with uwsgi. The problem is that none of the images are loading. When I go to example.com/static/gradient.jpg it works. The images loads. But when I go to the website, it's giving me 500 when trying to load the image. Does anyone know why this is happening?
In the image below, the app directory holds settings.py and the other "admin" files. The urlshort directory holds the django app files, like my templates, models, views, etc. All my images are located in the static directory. In my settings.py I have urlshort/static as the STATIC_ROOT.
I think I found the solution
urlshort/static is the wrong directory. Does anyone know how I could change it to /static? I tried changing the STATIC_ROOT directory in settings.py from urlshort/static to /static/ but that didn't work. It's still trying to get the images from urlshort/static.
serving from nginx not django. django doesnt serve files in production mode. so youll have to modify from nginx. at least thats my guess @mortal mango
so in my .conf file?
@wicked elbow
# the upstream component nginx needs to connect to
upstream django {
server unix:///home/internet/AtomURL/short_url.sock;
}
# configuration of the server
server {
listen 80;
server_name atomlink.tk www.atomlink.tk;
charset utf-8;
# max upload size
client_max_body_size 75M;
# Django media and static files
location /media {
alias /home/internet/AtomURL/urlshort/media;
}
location /static {
alias /home/internet/AtomURL/urlshort/static;
}
# Send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /home/internet/AtomURL/uwsgi_params;
}
}
this is my .conf file
i dont know anything about nginx configs unfortunately, im just telling you django doesnt serve files in profuction. your actually better off moving your static files to a seperate server and linking to them there
i use aws s2 for my static files, as for uploads, the correct path should be set in your database once its complete i would assume, havent tried yet
Just install whitenoise and pillow.
Does anyone have solution for Flask not serving static files? I'm using the Flask default url base endpoint /static for static files, and that's how my template files reference them like href="/static/css/main.css" or smth like that. I'm currently using the Flask server for that and am not planning on using Nginx or any other web servers just yet. I swear it was working fine just yesterday and now it's not today, the web page looks crap without css and favicons. I even tried clearing the browser cache and cookies and trying different browsers but still the same results, does any have a solution to this?
Hello I'm looking for some help with Django-tenants.
My project is a work order management system for mills. I have a postgresql database where each schema is a different mill location. How would I be able to switch between locations(schemas)? currently I do this
<li>
<div class="container-fluid">
<div class="col-xl-6 col-md-6 mb-4">
<a href="http://{{ mill.domain }}:8000/index">
<div class="card border-left-primary shadow h-100 py-5">
<div class="card-body">
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="text-xxl font-weight-bold text-primary text-uppercase mb-1">
{{ mill.domain }} </div>
</div>
</div>
</div>
</div>
</a>
</div>
</div>
</li>
Which works in a testing env but not when trying to deploy
Essentially I want to have a card with the name of the location (Location1) and when you click on that card it will take you to the index page for that location. Which would have the domain https://location1.workorder.com
don’t you think the input looks more modern
there is literally NO app or framework I can think of that uses square black border in 2021
thats the exact copy of from youtubes comment section. thats not a square black border
unless your talking the buttons border
no I mean
the old one
lol i know i changed it the youtube comment bar, and reply bar. it took like 10 minutes to do
okay
I know what turns me off
for the button
it’s too dark
accessibility issues
so basically there’s a guideline that says
you should have a certain contrast ratio
for all your text
this is especially important for visually impaired users
I’m eyeballing it but my gut feel is that the shade is a bit dark
so it might be hard for some people to see
AESTHETICALLY it’s not a problem (and would be subjective anyway)
button only shows when the comment input has been entered. and the button clocks in at 10.01 and chrome says its good in terms of contrast. its not black on white. thats like a 21, but anything above like a 4 is considered ok in chrome
also
re: positioning
this might be useful if you haven’t read it
okay then
I’m not good with colours tbh
my colour vision is average to below average
so I’d say go with what Chrome says
also I’m seeing it with night mode on
what’s your font size btw
the logo i need to make darker, because that tan is to light on white. just havent done it yet
im using a 12px standard, links and headers are 16 i believe, but headers are bold as well. some things are 10px. looks good on my pc 1920x1080. might be large on smaller screens. i need to convert to em
i lied, the font size in that comment section is a 14px
i dont like large fonts, but i could see 12px being to small. like i said stuff like the timestamps are 10px on the comments. i had the font bigger, but it seemed to big
it felt really big
when I changed
but I’d say the guideline exists for a reason
I can personally make do with 12
and honestly it’s a PITA to handle 16 on mobile
you run out of space super fast
I guess the question is: how much does accessibility matter to you?
okay so if you look at that picture, the username is 16px, the creator is 12px, the comment is 14px, and the timestamp is 10px. which is why it may look slanted to some.
not slanted
I think the RATIO is good
but the comment is basically body text
which might be a bit small.
is all
it’s not egregiously tiny
yea, fonts/sizing/spacing i planned on working last. its a whole job in itself. im just trying to make the user not scroll to see content. like i think youtubes fonts are to large honestly. and thats running 1080p. sizing is one of those dumb cases. that some things are good for some people, but to small for someone else and vice versa
are you planning on making a mobile version?
already have one. and it looks good on my phone
on desktop you have a ton of space so you can change fonts later
but IME
increasing font size on mobile is nontrivial
all of a sudden you have two buttons that can’t fit next to each other
which is just 😦
yea, i ran into that issue. but my mobile site cant be zoomed. so i dont have to worry about it not fitting
huh
I don’t get it
what does zooming have to do with it
i guess nothing. zooming isnt the same on mobile as it is in a desktop browser. my bad
ive converted anything that doesnt need to be text it icons. so font size dont matter so much
there is a bug in that in case you look at it. the register will register you, but itll white screen you. i fixed it, just havent updated the code yet
are they easily understood by users
okay again IME
i google the icons and modify to my color scheme
after I started user testing
I realised HOW UNINTUITIVE SOME ICONS CAN BE
or rather
how much potential for misunderstanding
so I redesigned more or less everything to either be text only
or icon and text
i suppose my text is a little small on mobile, at least in the browser dev tools
because there were times I was thinking “obviously this icon is appropriate”
and my user would be confused af
it gets worse for older people
etc.
and when you have relatively low contrast AND small text
it can be hell to read
is why 16px is the reco
in general, not your site
lol if the site takes off, the first person i hire is a UI designer. cause i just dont have an eye for it. i mean ive only been doing this for 2 months, and wearing all the hats mediocrely. theres like 300 some files to be the site that it is. its insane.
im also changing the timestamps to be relative to now. so itll say 10m ago or whatever, just not been a top priority. trying to shrink things that dont need to be big to not be distracting
Is building APIs from scrapped data something people do? I want to scrap my countries covid-19 data from the government website and build a graphql api from it.
I'm not exactly sure where to start though. I want to be able to host the API somewhere online and people can query from it and get the data. Could anyone point me in the right direction please?
how would i make a website responsive lol, i looked on youtube but they didnt rlly help
Use bootstrap
ok thanks lol
@hybrid bobcat Have you referenced your HTML pages to your CSS file with the following line: <link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}"> If you link your CSS files like this, it should definitely solve your issue and therefore should render your webpages
yeah UI/UX is a huge field
well yea i tried it, didn't work, i ended up having to create my own views for static files and it solved the issue
it's not as fluffy as many people think tbh
and when a site isn't designed with UX in mind it shows
Hi, currently setting up a mail server. Is there any norm (like a IEEE or RFC) for mail names that should exist?
For example: admin, mail, info, noreply, ...
Any way in getting creative? 😂 😂 😂
|| Im just kidding ||
i just moved from flask to quart
and my wsgi needs to be asgi
if __name__ == "__main__":
app.run()```
this is wgsi
how do i make it work for asgi?
ping me
music = open(r"extra/music.mp3", "rb")
<audio autoplay loop id="myaudio">
<source src="{music}" type="audio/mp3">
</audio>
```So for some reason my code doesn't work before you say anything rather than my file problem I tried a music file from google and it worked so it's my local file that's a problem!
what is this python + ?
what
I mean <audio ... > is in python file itself?
music = open(r"extra/music.mp3", "rb")
its an html file
This line is python
i wont show all
I think you only need to provide path to the static file
so browser can fetch it from server
What error did you get?
hey i got a quick question. I made some updates to my domain site and it works perfect locally, but when i try to update the domain via file manager on cpanel, it comes out different
Hi, I need to use Jinja2 to copy values, the main aim is to automate a testing process, I've never worked with template libraries, can I ask about Jinja in this text channel?
hey guys, what module do you recomend more. flask or django
@cloud kestrel i love flask. it is simple and easy to use and you can expand it as much as you want. django is the opposite, but more powerful from the start.
hey there, i am new in django. Is there any mentor/project to join for a practice?
i have a question regarding streaming data in flask. my problem is this: i have a route that makes various API calls to update a dataframe. This takes several minutes. I want to run this route once a day in the morning with cron-jobs.org, but now that i deployed it to heroku, it sends a timeout after 30 seconds. The heroku timeout variable cannot be altered. But i thought i could send data after some seconds until i finally return success after updating.
i thought a way to do this is to yield some simple response while the function is running. does someone have a good and simple example how to do this in flask?
how do i show user a file picker to save a bunch of data to disk?
def load_user(user_id):
return User.query.get(int(user_id))```
This is giving me error - TypeError: user_loader() missing 1 required positional argument: 'callback'
Isn't that a decorator?
you should remove those parenthesis
Hello, am trying to get cookies and django work for my cart in Django app.
Now ive run into problem.
cookie before paid..
{
"143":{"25":{"quantity":3}},
"None":{"25":{"quantity":3}}
}
when i pay i need to delete user and his cart from my cookie am using this:
def update_cookie(self, response):
user_id = f"{self.request.user.id}"
cookies = self.request.COOKIES
cart = json.loads(cookies["cart"])
del cart[user_id]
response.set_cookie("cart", cart, max_age=settings.EXPIRE_DATE)
"{
'143':{'25':{'quantity':3}},
}"
where is the problem ? bcs then i cant use it as an object in my js even if i use JSON.parse its still a string
dict can't have duplicates right?
yeah it's working fine for me in a scratch file
import json
cart = '{"143":{"25":{"quantity":3}},"None":{"25":{"quantity":3}}}'
cart1 = json.loads(cart)
del cart1["None"]
print(cart1)```
hey, I'm new here, how do you get python highlights?
got it!
but am parsing this is javascript then like this:
let cart = JSON.parse(getCookie('cart'));
if(cart == undefined){
cart = {}
document.cookie = "cart=" + JSON.stringify(cart) + ";domain=;path=/;" + getExpire();
}
and result is always string
what question do you have about this?
still the same why am i getting string in js when am parsing this from cookie:
"{
'143':{'25':{'quantity':3}},
}"
Can you post the before (python) / after (JS)?
It looks like you have a dupe key
its fixed now, but wdym by dupe key ?
i dont have duplicate keys
that "25" and "25" is in other object
'25':{} was in both main keys. Because you were getting unexpected counts of results that Could* have been because of what you were calling out of them
I could be wrong, I didn't fully understand your question
im starting to learn how to make websites and want to incorporate python into this learning. should i be going full into learning django or just use flask? django seems harder but im just looking for opinions if its worth it to just do more django
if you want to learn, use flask. it's a lot more "hands on" in a sense. in django, a lot of the stuff is already pre-made and it's a bit less "hands on" as you're using django premade models etc.
exactly what i was looking for 🙂 thanks. ill go with flask
i think you will end up gravitating towards django in the end, it's great to have a grasp of both though... that's how i started.
flask seems easier to "get started" from what i am seeing as well
once I did a good chunk of flask, i actually started looking at django and I hated it so much, now I can't even remember how to make an api in flask lmfao
yeah it's a bit more beginner orientated, I think it has more guides/tutorials for beginners
and iirc codecademy has a course on Flask, it's pretty good
ill have to check it out. yeah i started something in django and it was quite overwhelming tbh
the only reason I switched from flask -> django because looking at local job markets django was 2x in demand to flask
so just keep the long term in mind
but for fundamentals it's great
yeah thats what im looking for is the fundamentals. as long as it isn't like a terrible transition to django in the end then 👍
oh yeah you'll be fine, the knowledge on what to do carries over, its just the how which changes. and all that changes is you'll just need to learn the django syntax
thanks. helps me a lot. was getting discouraged by starting in django lol
Hi All! Im trying to use Zeep for sending a SOAP request, the thing is that the request needs an attachment I cannot figure out how to send it. my request should look like:
<soapenv:Body> <ws:uploadContent> <!--1 or more repetitions:--> <uploadContentBeans> <number>1315856</number> <!--Optional:--> <revision></revision> <!--Optional:--> <iteration></iteration> <objectClass>Document</objectClass> <contentType>PRIMARY</contentType> <!--Optional:--> <limitedDownloadAccess></limitedDownloadAccess> <!--Optional:--> <securityLevel></securityLevel> <fileName>test.txt</fileName> <dataHandler>cid:test.txt</dataHandler> <checkinComments></checkinComments> </uploadContentBeans> </ws:uploadContent> </soapenv:Body>
As you can see we have fileName and dataHandler that references the name of the file to upload, but how can I attach it to the request?
Anyone here running large mature codebase on NodeJS or Python (with MongoDB as the database)?
Is there a way in flask to only allow a user to access a route by being redirected? Like they cannot simply type the route in the browser of something, they have to fill a form, and then be redirected to the route. if they simply type the route in the browser, they should be redirected back to the index page.
I would like to use profile_form.instance.class_key in other views or make it a global variable.THe profile_form.instance.class_key variable only works on the register view('home.html' template).How can I make it work in other templates too? views.py
def register(request):
registered = False
if request.method == 'POST':
user_form = UserForm(data=request.POST)
profile_form = UserProfileInfoForm(data = request.POST)
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
user.set_password(user.password)
user.save()
profile_form.instance.class_key = request.user.class_key
profile = profile_form.save(commit=False)
profile.user = user
profile.save()
registered = True
return redirect('/login/')
else:
print(user_form.errors, profile_form.errors)
else:
user_form = UserForm()
profile_form = UserProfileInfoForm()
return render(request, 'home.html', {'user_form': user_form, 'profile_form':profile_form, 'registered' : registered})
I defined the forms and the models.
``` please help me...
request.session['key'] = value then you can access this session within other views
what is considered advanced django? I haven't learnt anything new for django in a while now.
Is there a way to have a flask error handler only apply to a specific path?
like only on /api/*(so I can return json error responses) but returning the default html error pages anywhere else
Really, they are the same, but beginning with flask is a good option
I started with django though
yeah just from the hour i've put into flask now i feel i am lot more comfortable then i was jumping into django lol
Django is huge though ( using the default django starting )
I have seen flask and it does seem alot easier than django
But if I were to give an advice to my younger self, I'd tell myself to start with compiled lagnauges instead lul
can you do this?
def create(self, request, *args, **kwargs):
serializer_class = CommentLikesPostSerializer
return super().create(self, request, *args, **kwargs)
``` change the serializer for just the create method?
yep but i dont know if it works with returning it or not
should call the the default create im pretty sure. imma try it anyways haha
but it should work
dont return it and i tried it actually with save methods of models
like super().save()
but anyway see how you do it
since i have foriegnkeys, i need different serializers for the post, cause otherwise it doesnt work correctly
man, i make way to many migrations, good thing this is just the development database
why do peoples django code snippets look so huge? all of my stuff looks tiny compared to their code
hi. i have a simple question when i finish my project i have put him in a public server but if i search how to do this all of them tell me to buy something call domain and server ,should i buy them or can i do it for free like i make them?
Hope that's is clear.
im using AWS servers for my project, youll want a domain though if you want a unique link for your page, most are pretty cheap, some as low as 8$ a year. but some hosting places, give you their domain to use. so up to you
@wicked elbow ok, i also want to know something ,if i done all thing (buy domain and server) the website will be work all time
servers are extremely expensive if you buy one for yourself, you can host in a bunch of places for little to no cost as long as there isnt heavy usage. if you have those 2 or even just a server, you app will run as long as the server is online
@wicked elbow thank's for help ❤
def get_serializer_class(self):
if self.request.method == "POST":
return CommentLikesPostSerializer
return CommentLikesSerializer
``` that was the solution in case you wondered
How can I make a portfolio website with python?
I know html and css
I'm trying to learn flask
but I don't want anything too hard
JUst something simple for fun
Is there anyone who would like to help me with django urlpattern?
sure
I want to create endpoint like 'admin/create/<ip_address>/", but I dont rly know how to create regex for this
ok
first you have to be carefult cause /admin is already used by django
are u aware of that ?
oh yes, u right
u can use a different name in development
Ill change it for api/create/
Btw, I've created regex for retrieve it look like this r'^(?P<ip_address>(?:(?:0|1[\d]{0,2}|2(?:[0-4]\d?|5[0-5]?|[6-9])?|[3-9]\d?).){3}(?:0|1[\d]{0,2}|2(?:[0-4]\d?|5[0-5]?|[6-9])?|[3-9]\d?))/'
this is how it's done
i am not that good at regex
u can just use variables like that
then in views
the function should accept two arguments
def view(request,ip_address):
then u can do regex on it in the view
there are a lot of other data types, other than <str:>
DRF ?
django rest framework
I'm affraid that this pattern will match anythink I put to the url
you can then check for the ip
in the view
match the string with how a proper ip address should look like
so I can do sth like validation in the view, right?
yes exactly
sounds good
imo that would be cleaner
yeah, u right
thank you a lot!
I can't seem to get the ip address
am i missing out on anything by using functional views > class based views, for django?
its the same
Both of them can do anything
I use Function based views in most of my tutorials and recommend them for most beginners, here's why...
Be sure to checkout my latest course on Udemy, "Django with React | An Ecommerce website"
Link: https://www.udemy.com/course/django-with-react-an-ecommerce-website/?couponCode=387F19CD4087385E87C1
Here u go
More context
Hello,
I am trying to make a lister Item web app with HTML Sass and JavaScript, which let the user add items in a list and removing them at will. I have also provided a search feature so when the list goes long, User can find an Item easily to maybe remove them. ‘Now I wish to add a feature that prevents adding the same item more than once.’
I have tried to get the HTML Collection of the list items present in the list and making it an Array and looping through it to make sure if the list item to be added is already present.
I even tried to compare their textContent and after console logging them,they are same but for some reason when I compare them, they are not same.
I tried some other methods
Nothing worked…
Please help me!
You may visit this link to see the code right into your browser
https://github1s.com/RocTanweer/FrontEnd/tree/master/Projects/ItemLister
Just to to ./Projects/ItemLister
Thank You
@glacial orchid How exactly are you comparing the elements in the array? That sounds like the correct approach
I am getting the main list and containing it in a variable
then getting all the 'li' as HTML Collection
converting them into array
looping
The fact is I am creating a list item same as an item already present
and them I am comparing if they are equal
But they are not
Even though they look exactly the same
If I cant compare them correctly, How am I suppose to prevent duplication?
I just need to know how to compare properly
Their tags are same
their class are same
Textcontent
button
everything
Can you point out the exact line where the comparison is being done?
I can't find it
Since they were not working yesterday
I deleted them
you want me to show you?
If so
wait a bit
yeah please do
comparing the first child of new list item and existing items
on console logging
they are same but on comparing it gives false
See there are two items in console
one is what I created
and other is first element of the already existing lists
they are same
but comparing does not work
Here this pic's code
Note: I am not appending the newItem here thats why its not added into the list here
Instead of comparing the elements themselves, try to compare the innerText attribute
The reason that comparison doesn't evaluate to true is because the Teo elements you are trying to compare are different nodes
def login():
if current_user.is_authenticated:
return redirect(url_for('home'))
form = LoginForm()
if form.validate_on_submit():
user = User.query.filter_by(email=form.email.data).first()
if user and bcrypt.check_password_hash(user.password, form.password.data):
login_user(user, remember=form.remember.data)
return redirect(url_for('home'))
else:
flash(u'Login Unsuccessful. Please check username and password', 'danger')
return render_template('login.html', title='Login', form=form)```
I am not able to login despite writing this peace of code
peice*
when i enter the id and password which I have registered into my database and hit login, the password field gets empty and nothing happens.
Hi, I'm trying to use Jinja to pass values from an excel sheet to an automation script as the API has only custom data types, so I can't pass arrays to it. Someone recommended me to use jinja/mako as the values would be hard-coded. I believe I would have to extract the values from my excel sheet in a separate script and then use Jinja to pass them on to my main automation script. I do not have any experience with template libraries. Is there anyone who help me get a better idea about this whole process? I'm not able to find many examples where Jinja is used to pass values from one python file to the other. Thanks.
I basically want to define the datatypes in my main script and use them as placeholders to pass my values to iteratively.
please give me more detail
Can I make a website without HTML/CSS/JS just python?
nope
ah this bad news
yeah but it is hard
no
How?
these are not even considered programming languages
ah nice
and dont use PHP, php is hard
Just because they are not considered programming languages doesn't mean it cannot be hard for someone
I'm terrible at photoshop for instance.
IME
most people who say that HTML and CSS are easy have not fully apprehended their complexity
just my two cents
hey
i know python and python and mysql and i want to make web with login system.
how i do it?
just learn to use flsak/django and add the sql database+ code to there
@vestal hound Definitely, it might not be hard to make some basic static html pages with simple css but the real deal is when you start with more complex frameworks such as Vue.js, React and what not, Scss, perhaps bulma, boostrap, tailwind.. etc suddenly you don't make simple static pages but Full fledge web sites, SPA's with tons of api's and we are not even talking about making it all beautiful and sensible which is a whole new story.. hell there are a hundreds of things I'm missing in this comment, there is way much to it than 'css and html is ezz lmao'
ah ok thanks
well, my opinion about django is that you don't really have freedom to add your own functionalities.Most things are built in adn it s hard to implement your unique ideas.
But i only know django and I can't compare it with node or orher backend frameworks
so
if anyone can?
is it an option to make site without flask or django
its all wrong you can customize it
html and css for front end then python and mysql for back end
yeah.
CSS animations
flexbox
accessibility concerns
there's a lot of detail.
actually, HTML and CSS are Turing complete
of course, in a practical sense they're not really programming languages in the same way
that doesn't change the fact that it's not easy to do HTML/CSS well
@vestal hound since you said it didnt look modern enough, what do you think about that? put a lot of work into it yesterday
defo looks a lot more modern I gotta say
not sure why your text looks a bit gritty? could be just compression
not really sure about the positioning of the icons though
also correct me if I'm wrong but
new comments will appear at the bottom, right
image i think, the text username is 18px, text is 16.
so why is the comment input at the top
principle of locality
thank you for your commitment to accessibility
btw did you check your contrast ratios?
so if theres an entire page of comments you dont have to scroll to the bottom to leave a comment
why not sticky to bottom?
is a design choice though
up to you
that's how Spotify does it too
and yea, eveything checks out in chrome
yeah my worry is just that
with the icons there
it'll get quite chonky
if there are many comments
wait sorry
what's the reply icon for?
Guys, I'm losing will to live over my project. My Flask endpoints work nicely in dev but none work in production on PythonAnywhere:
Flask:
...
...
from flask_cors import CORS, cross_origin
blog_blueprint = Blueprint('blog', __name__, url_prefix='/blog', template_folder='../../templates')
CORS(blog_blueprint, resources={r'/*': {"origins": ["https://www.coinme.com"], "allow_headers": "Access-Control-Allow-Origin"}})
@blog_blueprint.route('/fetch_current_rates')
@cross_origin()
def fetch_rates():
...
...
return jsonify({'status': 'success', 'usd': usd, 'gbr': gbr, 'eur': eur, 'czk': czk, 'ngn': ngn}), 200
React front-end:
useEffect(async () => {
const config = {headers : {"Access-Control-Allow-Origin": "*" }};
const resp = await axios.get("https://www.mydomain.com:5000/blog/fetch_current_rates", config);
...
...
}, []);
this is what I'm getting in the console:
its only loading to 20 comments, and no replies, the rest will be pulled in. i thought the same thing, goes back to screen sizing though. to big of a screen and buttons on say the left side look bad
do you know what CORS is
like how it works
responsive deisgn?
cross origin resource sharing
it determines which domains will be allowed to consume resources or data from endpoints.
ye basically
okay I don't know how Flask handles CORS but
you should inspect your headers
the biggest thing is i want it to look the same everywhere you use it so i dont want to make it side buttons on some and under the comment on others
hm
why?
ease of use. sites are one thing to impliment that in. say the difference between m and desktop versions, but comment sections, you dont want people to have to constantly shift what they know depending on their device. if i built an app though, they would be on the right side as butons
I think mobile vs desktop is fine
if you mean this with respect to different screen sizes
fair enough
im getting there though work in progress. id have never guessed comment sections actually took so much to make them work, like 500 lines of code for just the react code to make it work like that
Seems like you haven't read what I explained
I have already tried what you said yesterday...
After console loggin their inner text they looked same but false when compared
i have this html (using bootstrap. i dont fully understand html yet). how would i update this without a refresh from python using flask?html <textarea class="form-control" id="exampleFormControlTextarea1" text="test" rows="12">{{ result }}</textarea>
use javascript. only way to update static pages without refresh
if you wanna prevent the page refresh you gotta use javascript axios or fetch api or ajax you cant do it in python
try add / at the end of url on frontend, I had similar problem
alright thanks. ill have to look into simple javascript then i guess. i dont need it for design or anything. thanks @wicked elbow @nimble epoch
yvw
you would say that would be a simple task? 
what would be a simple task?
refreshing an element without a page refresh
of course
okay ill do my research. thanks
yw but i suggest you to go for axios
i mean i wouldnt call javascript a simple task. minor modifications are simple, but using a framework is complicated. React, Vue, Angular are sites completely built in javascript
true
def login():
if current_user.is_authenticated:
return redirect(url_for('home'))
form = LoginForm()
if form.validate_on_submit():
user = User.query.filter_by(email=form.email.data).first()
if user and bcrypt.check_password_hash(user.password, form.password.data):
login_user(user, remember=form.remember.data)
return redirect(url_for('home'))
else:
flash(u'Login Unsuccessful. Please check username and password', 'danger')
return render_template('login.html', title='Login', form=form)```
I am not able to login despite writing this piece of code
when i enter the id and password which I have registered into my database and hit login, the password field gets empty and nothing happens.
How can I get the query params for a url like this:
http://127.0.0.1:8000/api/auth/#access_token=........&expires_in=315360000&token_type=bearer&refresh_token=......&account_username=....?
I tried request.GET and printing *args but it's empty.
in django?
yep
self.request.query_params.get('param_your_looking_for', default=None)
then you'll do an
if VAR is not None:
do something here!
my query_params is empty, probably because the URL in question is in the following format:
<base_url>/#key=value
instead of the usual
<base_url>/?key=value
possibly?
?? that's not what hashes are for
I don't know anything about query params
oh yea, without the ? you dont have query params
<base_url>/#key=value <- ill-formed URL
# is used to identify fragments
actually it might not be ill-formed I'm not sure if = is a valid identifier hm
and you can use them to focus the screen
Oh I see:
The fragment identifier introduced by a hash mark # is the optional last part of a URL for a document. It is typically used to identify a portion of that document.
The part after the # is info for the client. It is not sent to the server. Put everything only the browser needs here.
so if your id="Footer" and you do #Footer itll focus your footer
#foo will focus in any of your id='foo' elements
oh damn, so there is no way for me to extract that info from the URL
http://<base_url>/#test=1 in my case it's like this, with the fragment
and that's not sent to the server
it's an external API, I can't
Oh...
The access token is returned to your application in the fragment as part of the access_token parameter. Since a fragment (the part of the URL after the #) is not sent to the server, client side javascript must parse the fragment and extract the value of the access_token parameter.
A bit more reading on my part would've solved all my doubts
Makes sense haha
I was about to tell you that you could configure your webserver to add a cookie or header to the request with the full raw URI
I was going to start my own imgur API package for easy usage, so I wanted to automatically get those parameters, but I guess the user will just have to do that part themselves
Hi Im using Django and was trying to do an order_by on a queryset after already having used distinct. I get the error that I cannot do that since they need to be on the same field. Is there any other way to do this since I want them to be on different fields?
hey, im using requests-html to do some webscraping. How would i find the meta information?
Hi Im using Django and was trying to do an
order_byon a queryset after already having useddistinct. I get the error that I cannot do that since they need to be on the same field. Is there any other way to do this since I want them to be on different fields?
@sullen basalt Do two queries using the value of one into the other one or just get the distinct query and then use sorted() on the object list
im trying to get my information through a python script running in the back ground. i am reading that i can use ajax to call python in javascript. am i on the right track you think to get a python script information through axios essentially?
axios does this exactly but its eazier than ajax. search the differences on google if you want to. and ye you can use api to send or get informations
ahh okay so that is built into axios then essentially? i dont necessarily need to make an api i dont think? what i am making is just needing user input to run through a python (selenium) script that is running and then print results into a text box
oh ok
would this need an api? nothing needs to be stored at all either
so what is going to be requested?
i believe what is being requested is the information from the python function that gets run?
ok imagine you have something like localhost:8000/users/ that displays all users or a post request you want to send data from frontend so when you want to get or send data you add the location that you want to get or send data to. get it? like (localhost:8000/users/)
and that view or class function has a route right?
if im right it was like @route('/path/') in flask
yeah i do have the page routed like that
so get that by that
sorry i am extremely new to flask and web stuff so trying to break down things to understand 🙂
its all ok😉
but i forgot flask
im slightly confused get what by the route?
the python function?
or in axios?
you want to get data from the function that you defined
so axios.get('something.py')?
like imagine a function that displays all users like return User.objects.all()
emm no not the file name
the route
got it?
partially i believe
and i dont know something
i dont know what you gotta use in flask to intract with frontend
or maybe nothing while you are doing it in the same address
i dont know much about flask
yw
first real web project i am doing so a lot of terminology i am learning now lol
well more so what the terminology actually means and does lol
wish you luck
i want to lear Django can i gets some tips for beginning
https://www.youtube.com/c/veryacademy/playlists gr8 channel 🙂
veryacademy is where to come to learn to code for free. Learn website development, tutorials on Python, Django, PHP, HTML, CSS, JavaScript, Bootstrap, WordPress, MySQL and much more.
This channel is all about teaching you simple actionable code, providing you access to code examples that you can use, for free to develop your knowledge and learn...
learn from the official site THE GREATEST TIP
Yep, read the docs. Its very documented
thanks @toxic flame @nimble epoch @amber oxide for helping
this my code for login:
when my login is successful it renders index.html
I can see index.html but url don't seem good as i need 127.0.0.1/ after login
can someone help me
This is the normal url pattern what is the problem you have?
i dont want to see doLogin, i need 127.0.0.1 after login
actually when i go to :
127.0.0.1/login i get login form
127.0.0.1/doLogin process my form and provide response
and for successful login it sends me to index.html
but url doesn't change
Hey people, anyone here familiar with pyppeteer?
@wicked elbow it's night
Will try and let you know 🙏
Guys, I made a web framework, but my 404 and 500 error pages aren't working, I get the following error when my code tries to render it https://paste.pythondiscord.com/ebuyuqenoj.sql
Hi everyone, I was wondering if anybody had advice how to display data from an api to a view through django
hey can you please tell me how can I understand concept in flask
Bcoz the syntax are bit hard
and I m not getting any resource that can help me
please help
the best information about this error is that your templates can not be found
Yeah, but Im passing the absolute path
If I do it from the shell, it works fine
but when I import it, it doesnt work fine
if you real beginner you should watch a video on youtube
I have tried them but still can't get the concept
what you mean concepts?
Me?
yep
like the SQL Alchemy is bit tuff
I've deployed it to pypi
and it is the most important part I think
there are two books
please tell
ok wait
but for beginners
you should first learn pure sqlalchemy
okay then
i meant the web framework that you using
if you are using
I made the web framework, to run it im using cherrypy
Its a WSGI framework
So I can use anything to run it
oh so this is your own framework?
Yeah
so you gotta tell us whats the solution lol
I'm assuming you are using django. The problem here I believe is that you are just rendering index.html. This is basically saying that when you go to doLogin and the login details are correct, render the index.html file. You never tell the url to move to the index page. What you could do instead is make a redirect to the link of the index page (see https://docs.djangoproject.com/en/3.1/topics/http/shortcuts/#redirect)
Tho you don't really need a new view to act as the middle man between login and index. You could just add that logic to the original login page itself
can't he just redirect to the other view instead ?
Yeah I said that in the message above that one
what's the right way to set per-request timeouts in a flask app served by gunicorn with gevent workers?
EDIT: answering my own question, use gevent.Timeout like so:
with gevent.Timeout(time_in_seconds, exception_type_to_raise_on_timeout):
do_some_work()
Yeh sounds like it
calm
Not sure which channel is the right one for this, but anyway I have a flask API where I POST commands and the command can take up to 30 minutes to run on the server. Is there a standard way to somehow get the progress of this task to my client?
maybe if i post a generated hash with the command and the server stores the progress in the database with this hash, then i can poll it..?
@silver pollen the way I'd handle something like this is, I'd create a db table that functions as a work queue. When someone submits a task, it gets put into that queue, and they can then visit a page that looks up the job ID for it to see if it's finished.
and you can also have it so that any new submissions to the queue purge anything older than X days or what have you, so it doesn't get too unwieldy.
@cerulean vapor yes something like that is what i thought about, but my problem is i can't return the job id because that would close the request and the job is not run. that's why i thought maybe the client can generate the job id and send it. if it already exists (which is extremely unlikely) the server can return an error.
@silver pollen You don't want to have the client generate a job ID, because the universal rule of client-server anything is you cannot trust client input
If the job in question takes that long to run, then you need to find a way to set up a job ID for it before it's triggered
yes i guess so, but this is for an internal app at work so i kind of trust all users. but maybe it would be nice to have an endpoint where i can request a job id and then send that in the post request.
I think that makes sense
the job ID can be logged in the backend, and then can be used later
i'll try something like that, should work.. thanks.
array.map()?
How do I map the keying dynamic and represent in a table
well as long as you json always looks the same you can destruct to
data.map(({title, items, subobj:{subtitle, querries}) => {
<h1>{title}</h1>
<p>{items}</p>
<h3>{subtitle}</h3>
<p>{querries}</p>
})
im not sure what your asking. if items is also an array, you just map inside the map
Hey there, I want to host a site that will showcase a random portfolio website. Is <iframe> the way to go?
Hi, I am looking for someone to help create a website that utilizes some music machine learning algorithms I created. Anybody who knows Django and/or JavaScript please DM me if you are interested! Also would like someone who is actively working, because I need to finish this project fairly soon 😬 . A developer who can do frontend and backend would be a godsend....
with someones permission? sure. without their permissions no. iframes can be broken out of though
@wicked elbow With permission of course, and that's my concern with the iframe, but I can't think of a better way.
iframes have major security issues. better just to link to them then do display them
I guess I can just host some JS to do a redirect to a random site too. Then there's no issue.
With permission. 😉
take a screenshot of them and display that, with a link to the site or something
You can also save their public html into a folder and display it inside a div
you could, but thats getting to the point of unethical coding. the whole idea seems sketchy honestly. thats like scraping reddit and redisplaying on your site.
iframes can link jack. basically gives the site with the iframe the same control the browser has
thats how you get your username and password stolen... lmao
?
Iframe just displays another site inside a box
Not sure how will someone steal your crede
maybe explain a little bit with more context
if you're free
correct, you cant see the address. you also cant see what the iframe is doing. iframes can be controlled completely in javascript. lol just google why iframes are bad
ok
no one uses iframes for anything good and everyone should have scripts in their code breaking iframes. very very few actual uses of iframes
videos are one of those specific use cases.... how else do you plan on transferring video data?
U still can change iframe link reeee
https://stackoverflow.com/questions/7289139/why-are-iframes-considered-dangerous-and-a-security-risk read that. think about it this way. for instance, if you loaded a malicious page that looks identical to say facebooks login page, you wouldnt know if it was a malicious link or the real link because you cant see the address
yes, and users shouldnt trust iframes. if your loading another site into your site, chances are your doing something malicious. like i said very few legitimate uses
Ah I see. So if someone puts your site into an iframe as well. It can execute js as if it was from that domain.
besides if i was paying a developer team 1 million a year to keep a site up the last thing id want is someone to iframe to my page and steal the credit of my site and display ads and make money from not doing anything but stealing my work
Hahahaha damn.
i mean im just saying 1 million isnt that much. thats 10 programmers making 100k a year.
Well
1 tech lead
3 full stack
Is probably all you need
technically speaking, iframes arent bad, but they can be
haha, look at facebook for instance or youtube or google. they all have way more then 4 developers. and no one hires full stack unless your a small company
4 full stack developer
Unless they hire by parts too ( fronted, backend )
Well I'll have to be applying for startups... I won't have a degree any time soon.
By the time i will be getting a degree. I'll be starved to death lol. ( If i dont have a job )
front end, backend, UI/UX and networking plus a programming lead and a project manager. is pretty standard. JS is a huge job for big projects
I assume full stack only contains fronted + backend?
Ui/UX & networking is included too!
?
Damn.
thats the full team for web yes
full stack doesnt do networking normally, but depends how small the company is
You seem to know kinda alot about this
ive done my research, in the next month im opening a beta to a new social media site