#web-development
2 messages · Page 68 of 1
They're the best resource imho and many people more knowledgeable than me recommend it too.
I wonder what WordPress uses
@molten quarry Hey
I have read that book you suggested till chapter 6, I have really enjoyed it till now, chapter 7 is about memory management, not something I am interested in and the next chapters are something like getting inside node.js and js's inner functionality.
I am planning to take a look at some major JavaScript frameworks, do you think the other chapters are necessary or something?
I'm learning about oauth 2 and I want to implement a flask app that makes a user login with discord and prints out their username and profile picture
I'm following this guide, but for discord: https://github.com/authlib/demo-oauth-client/blob/master/flask-google-login/app.py
My /login endpoint which redirects the user to discord works fine, and discord correctly sends the oauth code in the URL. However, when I try to exchange the code for tokens, that's when my flask app throws an exception authlib.integrations.base_client.errors.OAuthError: invalid_client: invalid_client
I'm not sure why this exception is being thrown
to exchange code for token shouldn't you use token = oauth.discord.fetch_access_token()
https://hastebin.com/ecefamihow
here's my traceback
please do let me know if you need any other info
hello all, what is the difference between django and drango rest framework? when to pick one over the other.
@stable plover it do be like that
Hey can someone help? I wanted to make a simple Flask app, so i started a template app from visual studio 2019, but whenever i try to start the local server, Python returns "UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 3: invalid continuation byte", i have no idea what's wrong or where it's wrong
I spent a week on google oauth. It is so unecessarily complicated.
@craggy lava can you post your trace?
@dense slate I would say once you understand the concept, it becomes more clear
I agree. Once it works, it's like "well yea, obviously that's how it works. Why didn't they just write it the way I now understand it."
Hey @craggy lava!
Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:
• If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)
• If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:
https://pastebin.com/FjTB1jLA
@stable plover here's the traceback from "flask run" last time i tried it on the console
what are you listening on?
are you making a url request somewhere?
see the last line of the trace
hostname, aliases, ipaddrs = gethostbyaddr(name)
I think something is up with name
I'll check the code, i just fired up the template on VS2019 and i'm very new to Flask, so i'll do some searching
Ran again from Visual Studio instead of starting from console, it says the wrong byte is coming from this part of runserver.py (probably the script that starts the server)
what is the SERVER_HOST value?
when set via environment variable
try replacing both HOST and PORT temporarily with localhost and 5000
SERVER_HOST is 'localhost' on the environment var
I'll see if it works
try replacing both HOST and PORT temporarily with localhost and 5000
Exactly the same thing
Also tried '127.0.0.1' just in case
OHGOD I CAN'T BELIEVE IT
MY MACHINE'S NAME WAS "ROGÉRIO" WITH AN "É"
SO IT WAS MESSING WITH THE HOST NAME
i have a class called loggedin and a class called loggedout on my flask app, i use these to know which style to use, but it doesnt work, thoughts?
nvm got it
@craggy lava huh? domain names are supposed to be UTF-8
can you file a bug report?
Yeah, i thought it was strange too as UTF-8 supports that kind of accent, i checked it just in case and it worked
I'll file a bug report later
@native tide have to be more specific
hey all. I'm in Flask.jinja.
any simple way of multiplying the string "more" by the loop.counter in jinja?
https://paste.pythondiscord.com/wejemubali.js
I want the output to be something like,
"some text..."
"some more text..."
"some more, more text..."
and so on.
@native tide I feel the same way, even after spending the last 2 months working through a Django textbook. However, like every programming language, what you don't understand will always look intimidating until you've learned gotten comfortable with it.
Find a resource and get goin!
hey all. I'm in Flask.jinja.
any simple way of multiplying the string "more" by the loop.counter in jinja?
https://paste.pythondiscord.com/wejemubali.jsI want the output to be something like,
"some text..."
"some more text..."
"some more, more text..."
and so on.
@icy wasp found it. https://jinja.palletsprojects.com/en/2.10.x/templates/#math
can someone guide me to the right direction
i know the basics of flask
like i can build a fully functional blog with flask but i wanna build more
is there other courses/tutorials i can follow to go more indepth into flask?
yep hold on
@distant trout it's a series that covers a lot ^
thank you! @marble carbon this seems to have a lot of information regarding flask 😄
yep
what are some front-end frameworks that work well with django
Quick q’s what is better for a beginner flask or django
Flask probably
When i want to run flask on linux for testing with sudo python3 app.py it doesnt do anything
do you actually have app.run() for testing
or have you been running it on your pc with Flask's cmd line
@quick cargo
i wouldnt bind it to your external address if i were you
Are you deploying this site?
whats your full code
The whole?
i run it
./?
It doesnt do anything
It doesnt matter where my files are located right?
i mean yes?
If youre not cd'd into the folder containing the file its not gonna run a non existant file
Apache or flask
Quart
Still doesnt do anything
stop saying Flask when its not Flask, it just makes life confusing
What is the exact command you're running?
🤨
Why??
Cd into the folder and run by saying
python app.py
This is if you have __name__ == __main__
i have it
What does it say
Still nothing
linux
I use quart
In the terminal
SET FLASK_ENV=development
flask run -h [yourIP] -p 8080
you will get following o/p on CMD:-
Serving Flask app "expirement.py" (lazy loading)
Environment: development
Debug mode: on
Restarting with stat
Debugger is active!
Debugger PIN: 199-519-700
Running on http://[yourIP]:8080/ (Press CTRL+C to quit)
Now you can access your flask app on another machine using http://[yourIP]:8080/ url
I found this on stackovflow
k i got it to run but its not accesible
with this command sudo QUART_APP=app.py quart run -h 0.0.0.0 -p 1000
hello
im using django-storages
and i get the following error
when i try to upload media files
'NoneType' object has no attribute 'stat'
Guys, how do I get started with learning building rest apis in python? I wanna use Flask. Apart from the documentation, are there any good sources you'd recommend?
I found this blog post did a good job to get you started: https://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask
In recent years REST (REpresentational State Transfer) has emerged as the standard architectural design for web services and web APIs.In this article I'm going to show you how easy it is to create a…
Thanks dude
I've trying to Google and stuff but I haven't had much success
I will check it out
Hey, does anyone know of a framework similar to Dash that is a bit more open ended on the front end? I'm looking to build an enterprise reporting tool with a Python backend and Angular9 front end and I'm curious what else might be out there to help abstract the transformation of a web request to an analytics DB query?
How do you create the ability to rollback in flask-migrate, if your migration failed? Because once I destroyed my database that way.
Or should I just back up my database
I'm trying to create a webpage in django that contains a search box. After submitting form data, it connects to a java library and returns the search term in a new page. I'm using django 3.0, so jython doesn't look like it's supported. How can I import a java library into django?
@vagrant owl I'd also look at FastAPI if just need APIs
@zealous siren FastAPI?
Yes, FastAPI
FastAPI framework, high performance, easy to learn, fast to code, ready for production
Aah, okay. Yeah, thanks bro.
I am trying to filter my posts by dates but it is not working with pagination - when I go the next page - the queryset is forgotten https://dpaste.org/O9A1
@limber laurel yes you should backup, also is there an option for an atomic transaction in flask, but how did your migration fail?
Hey guys so I’m working with Django right now and I wanted to know what’s the best software for caching memory ?
redis
are you making a cache to use in your django app?
Yeah I want to be able to store some data in the clients browser to reduce request time
I’m also new to memory caching
Easiest is memcached. However redis has more options that you can grow into, which for me makes it more worth knowing. Nothing wrong with memcached though, it works great.
Just started webdev, any tips from you guys would be much apreciated. Looking to use flask to put some of my python projects on here. https://tisbury.tk
@dark hare I had migrated my database and created a new column that is not nullable, dont know how I would bypass that in future, as today when migrating even with a default field, my previous objects had None inside of that spot instead of my default value, so maybe you know how I could make it use the default value
Is deleting the column an option?
@viral sphinx Neither is included. I know there is built-in caching, but it uses the database and is therefore slower.
This looks like a good tutorial on redis: https://realpython.com/caching-in-django-with-redis/
Could you delete the column, the recreate it with a default?
If all of it is null.
@limber laurel
Biggest advantage with redis is that you can persist data. So it could act like a second, very fast, database. Useful for storing values that change frequently (views on a page, stats, etc)
I want the get_choices_list() to be called every time the SampleModel is instantiated but that doesn't happen...how do i do it?
@dense slate Only one row ends up being jull, if I were to delete the whole column then my data would be gone
There is something called server default, will look into that
@warped falcon Put it in the init function then, since that is what runs when you instantiate an object
Right now you have it as a class variable
e.g. SampleModel.user_choice gives you the value, you don't have to instantiate it
Thanks fishy
I’ll look into it, appreciate it
Also what’s the different between memcache and just storing/caching information locally (on browser)
Would we have to use JavaScript for browser based caching ?
yes
@odd oar doesn't work, says self is not defined.
That's a glitch with your IDE, self is an argument to the function
But also that's not what I meant
@odd oarcan you show how to do it?
If you want user_choice to be different for each instance it needs to be an instance variable
so set self.user_choice to what you have now inside the __init__ function
🐍
Anybody Using Python for web development.
Yes many of us are
I am using Python. Is Node better than python for backend development?
if you have a lot of people working on it that know js better than python yeah
I am trying to connect these two text boxes however they are apart by a space. Originally, I just added all of them into <p></p> but that did not work at all. Anyone has suggestions on getting these two text boxes together?
hey guys
i have this
{% block content %}
<div class="row">
{% for product in products %}
<div class="'col-lg-4">
<img class="thumbnail" src="{{product.imageURL}}">
<div class="box-element product">
<h6><strong>{{product.name}}</strong></h6>
<hr>
<button data-product="{{product.id}}" data-action="add" class="btn btn-outline-secondary add-btn update-cart">Add to Cart</button>
<a class="btn btn-outline-success" href="#">View</a>
<h4 style="display: inline-block.float: right">
${{product.price|floatformat:2}}
</h4>
</div>
</div>```
i want it when i click View
it opens up a small overlay of the item and the item description
how can i do this ?
Guys
I wanted to start a twitter-like website
So which framwork should i use
Django or Pyramid
[ Flask is too micro for this, sigh ]
I'd use Flask, it depends what features you want on your app.
hi
well, DRF sits on top of Django as a sort of add-on
Django is big and has many features to learn
DRF is basically just another one of those features, once you install it
it's not that hard to work with
with drf you mean rest?
yes, Django is a web framework
DRF, even though it literally has framework in the name, is really just a Django application
it extends the functionality of Django
ok thank you
it's not a web framework in and of itself
one more question please, i've heard that django has more things built in compared to flask
so why do poeple still use flask
if django make there way easier
sometimes people don't like the things that are built into Django
they want more control
with Flask, you can still get those features that are built into Django - stuff like migrations, object-relational mapping, and so on
but you would install them as third party modules
to make everything from the begining
but then why does dajngo and flask exists why there isn't only one
haha
because everyone thinks they can do better
and then they try. and sometimes they do
oh lol
but that's good
having more variety
that's how capitalism works right
competition makes things better........i suppose
Django is wonderful. Flask is great too. They're different. Flask gives you more freedom to choose. Django imposes its really excellent set of tools.
Django comes with batteries included
I use Django for all my personal projects, but we use Flask where I work.
what are batteries
or were you joking
I use Django for all my personal projects, but we use Flask where I work.
@deep cave i was required to learn one of the 2 for a job and i chosed django
i was surprissed how could a company use both languages
batteries included is a term that means "comes with everything you need"
yeah i get it thanks
thank you for your explanation
you can find very polite people in this web servers
we try
but why do you use your time to help others
i've never understood that
and i have always wanted to ask
because when I was learning how to code, I didn't have a place like this to go and ask questions.
and I wish I did.
so I'm trying to be the change I want to see in the world.
yeah right when i started learning c++ at first it was the same
you're a good person
thank you
that's right too
you don't really know anything until you know it well enough to teach it to people.
see ya
you too
It is very difficult to iplement multi-user login in Flask
Like twitter
you mean users following other users etc
It is gonna be used my multiple users at the same time
Don't get you, but there are third parties that make the feature feasible.
Like, many user will be logged in at once, and it should mess thigns up
It is very difficult with Flask
User flask-login as third party and you shouldn't have a problem.
I'm not a daily Django programmer, but it is definitely feasible and quite straightforward in Flask
Choose the fw you're most comfortable with

Yea, both django and flask have third party for social login
Hi, Using django - I am trying to filter my posts with post_date and newspaper_title - was able to do so with only post_date but how to do it with newspaper_title as well or with only newspaper_title. Here is my code : https://dpaste.org/oTQu
Does someone have django example for discord?
Cause I am not sure if I wanna use django or flask yet.
Do you already have a project idea or do you just wanna learn ?
I have a project idea, it's a existing project done in wordpress that I am gonna redo in either flask or django.
Only requirement is discord oauth really
Ah
I used the pycharm option for django template
In both Django and Flask you'll probably use a third party library for that, so it's even
there's a lib called request_oauthlib which is what alot of people use
If you decide to use Django I absolutely recommend looking into cookiecutter to bootstrap your project
Actually I meant cookiecutter Django
Is Django still useful if I don't use their DB model at all?
And rather remote databases
thanksf or the cookiecutter thing
Is Django still useful if I don't use their DB model at all?
And rather remote databases
Wdym by that
you can and often do use remote Dbs with Django or any website
but yes it is still useable
altho its setout to very heavily rely off its orm
I downloaded django cookiecutter, and damn it is messy af
Probably not what I want so I be ditching it
It's just too much bloat for my use-case
well you can remove stuff you don't use
Hi all, would someone help me with this please? I'm trying to make an API request with Postman toward Telegram so that it sends an inline keyboard to a chat (I provide the id), but the problem is, the keyboard consists of an array of buttons, I don't know how to put all that in a request? Should I add it as a JSON to the body of my POST request?
Here's the "sendMessage" method: https://core.telegram.org/bots/api#sendmessage (notice the reply_markup parameter) and this is the InlineKeyboardMarkup: https://core.telegram.org/bots/api#inlinekeyboardmarkup
The Bot API is an HTTP-based interface created for developers keen on building bots for Telegram.
To learn how to create…
I am making a flask application, and I created seperate blueprints for commands and also one for injects, is that a good practice? As my other solution had all of these things be in the main application file
Also what is the difference between app_context_processor and context_processor?
hello
i have an error
https://stackoverflow.com/questions/62698392/javascript-stopping-django-views-py-from-doing-anything
ive described it well there
@sacred crest https://github.com/python-telegram-bot/python-telegram-bot
you should take a look at this, if you plan to make a bot with many features in the future
Thanks, I am using this module right now
and I've shown the inline keyboard, but I don't know how to realize whether the one who tapped on the button tapped on the "correct" button or on the "wrong" button.
I have this code which is working fine:
context.bot.send_message(update.effective_chat.id, "Let's test an inline keyboard",
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Correct", callback_data="confirm")],
[InlineKeyboardButton("Wrong", callback_data="reject")]]))
then I have CallbackQueryHandlers like this:```
CallbackQueryHandler(confirm_new_member, pattern="confirm")
(I'm not sure if it's the correct thing to use though...)
and then I attach this to the dispatch object, and let's say the function confirm_new_member is something as simple as this:```
def confirm_new_member(update, context: CallbackContext):
print(f"confirm {context.user_data}")
but it's only showing an empty dictionary whenever I tap on a button.
How to make a simple social media using py
you might do that using Flask or django
Can I DM you ?
just ask it here
@sacred crest
you would do something like
data = update.callback_query.data inside the callback query function and compare it to see whether it says correct or wrong
and remove the pattern argument for now, it doesn't serve you any purpose
Sorry for the delay. Thank you! I'll test it in a moment.
It's working
@marble carbon 🌮💓
Ay np
@limber laurel you should be apply to supply a default value for all previous entries for a new column, its straight forward in django but not sure how you apply in flask. Something for you to look up 👍
or you can just let all rows be nullable which would be your best bet
imo
hey guys! Am looking for django + react pdf crash courses. Anyone can help me ?
If you have good courses you can share it with me thanks
Yeah but if you have a good and complet youtube playlist i'll take
okay hold on
Okay thank you
and this
i haven't watched this exact tutorial since I haven't worked with react
Okay i'll check
@dark hare I found something called server_default it seems like it could do the job, but I dont hnderstand how to apply it from the documentation, a case of a non nullable column would be for example a profile picture, if there would be some kind of an icon there would at least be a default something, but if there is nothing then it cannoth show the image
That tutorial doesnt cover such thing from what I can see
ahh ok, i dont think i can offer much more help, other than to say would be best to search online for how to implement a default value for new db column using flask
but from what I can briefly see online it looks like you might have it with server_default
https://docs.sqlalchemy.org/en/13/core/metadata.html#sqlalchemy.schema.Column.params.default
theres also a default there specifically
Yeah, I just dont quite understand how the value definiton works or can I just do ,server_default=somevalue)
looks like you can just do default=
A scalar, Python callable, or ColumnElement expression representing the default value for this column, which will be invoked upon insert if this column is otherwise not specified in the VALUES clause of the insert. This is a shortcut to using ColumnDefault as a positional argument; see that class for full detail on the structure of the argument.
Contrast this argument to Column.server_default which creates a default generator on the database side.
Nope, I did dedault, for new object without anything in that field, it worked, but for old ones it just had None
what did you set default to though?
To No information
Just a string
And old objects returned None when querying that, but new ines with that field empty returned No information
hmm, maybe check these docs and check your code and try again
if not might be something else going on
but i would be confused if docs were wrong if you're doing it correctly
Maybe I need to change something in my configuration settings, gonna look into that with a fresh mind tomorrow, and if that wont work out I guess stackiverflow it is.
Thank you anyways
i'm being dumb
so the standard way of keeping passwords is a table in a database with salted hashes, right?
and somehow a static salt is bad practice?
how would you recalculate hashes when salt changes if you don't know the original pw and never actually keep it anywhere past the hash extraction process
@limber laurel thats a good idea, and no problem. Good luck
@bright badge you shouldnt really be messing with passwords. There are plenty of frameworks and libraries that take care of it for you. I dont see why you would be accessing user pws
Werkzeug both can generate the password and compare password hashes.
anyone familiar with django
A small bit, but a very samll bit
Hey everyone
Hi
I have a question, I am using flask, HTML + CSS to create a website
but
The navbar won't appear
HEre is the code + the directory tree:
main.py: ```python
from flask import Flask, render_template
app = Flask(name)
@app.route("/home")
@app.route("/")
def home():
return render_template("home.html")
if name == "main":
app.run(debug=True)```
base.htmlpython <!DOCTYPE html> <html> <head> <title>{% block title %} {% endblock %}</title> <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css')}}"> </head> <body> {% block content %} <header id="main-header"> <div class="container"> <h1>Mathoid</h1> </div> </header> <nav id="navbar"> <div class="container"> <ul> <li><a href="#">Addition</a></li> <li><a href="#">Subtraction</a></li> <li><a href="#">Multiplication</a></li> <li><a href="#">Division</a></li> </ul> </div> </nav> {% endblock %} </body> </html>
home.html python {% extends 'base.html'%} {% block title %} Home Page {% endblock %} <header id="main-header"> <div class="container"> <h1>Mathoid</h1> </div> </header> <nav id="navbar"> <div class="container"> <ul> <li><a href="#">Addition</a></li> <li><a href="#">Subtraction</a></li> <li><a href="#">Multiplication</a></li> <li><a href="#">Division</a></li> </ul> </div> </nav> {% block content %} {% endblock %}
style.css: ```css
body{
background: #e9e9e9;
color: #fff;
line-height: 1.6em;
font-size: 16px;
margin: 0;
font-family: 'Times New Roman', Times, serif;
}
.container{
width: 80%;
margin: auto;
overflow: hidden;
}
#main-header{
background-color: #fff;
color: #333;
}
#navbar{
background-color: #fff;
color: #333;
}
#navbar ul{
padding: none;
list-style: none;
}
#navbar{
display: inline;
}
#navbar a{
color: #fff;
text-decoration: none;
font-size: 18px;
padding-right: 30px;
}```
so yeah
IT's having trouble displaying things
on the webpage
Can anyone help?
Yes
I suppose it is doing exactly what you told it to do here
The mistake is how you're using blocks
In your base.html you have defined a block "content"
and filled it with your header and content
in your home.html you have inserted code outside the blocks
this code will not render correctly
you have also provided an empty override for the "content" block
this means the code in base.html no longer shows
therefore, no output
if you wish to override the content block, place your home.html override code inside the same-named block
guys, quick question, what's the equivalent of {{}} (jinja) for jquery?for showing values?
i have :
var number = 1;
i want to do like
{{number}} and it's rendered
Guys, where didi you learn django or flask?
Guys, where didi you learn django or flask?
@short marsh University of YouTube. Professor Corey Schafer is a good start and Brian Yu for CS50 (produced in 2018). This info is pertinent to Flask. I have not yet learned Django.
If anyone can help me understand why I cannot override naming the table in Flask through the class, see #help-pie please. Thank you!
@icy wasp ok i will try it thank you
this playlist: https://www.youtube.com/playlist?list=PLhQjrBD2T382hIW-IsOVuXP1uMzEvmcE5
and if you youtube 'Corey Schafer Flask' you'll find his playlist
For Flask backend
The front end dev basically works with the HTML folders inside templates and css/js files inside the static folder?
Who’s in charge of writing the {% %} in the HTML?
Sorry idk about web dev at all I just started learning about flask (on Corey Schafer)
What do you mean who's in charge of writing {%%} in html
You're in charge..that's a web template engine that works along with your backend variables.
So when the frontend guy is working on the HTML, the backend can work on the {%%} too? But simultaneous == merge conflicts?
usually the backend guy should do that, otherwise, if the variables are not passed as arguments in the render_template() function, jinja2 will raise some errors.
The front-end guy could mimic the effect of sth happening, for example, hardcode 3 elements instead of looping through the real data
and then the backend guy should come and replace those rows by saying sth like ```
{% for item in item_list %}
{{ item.name }}
{% endfor %}
Ohh okay
But we should never work on the same file simultaneously right
So backend should only replace the hardcoded elements once the frontend guy finishes and pushes to the remote
yeah, that's how I see it. There may well be other solns, but this is my opinion.
Okay, thank you for your time!
nw, good luck
How do i know how many requests are allowed to an api per time frame ?
2 requests per 2 seconds or 10 requests per 1 min like this
I know Jinja2 doesn't render JS variables; this is my case (where item.id doesn't work) ```
<a href="{{ url_for('portfolio.post', post_id=${item.id}) }}">
Solved it, quite awkwardly tbh, but this is how (for the curious) <a href="{{ url_for('portfolio.post', post_id='')}}${item.id}">
hey, does anyone know how to get a low-latency webserver network worldwide?
for example, I want to host a site which can be accessed in China/USA etc with low latency, so it needs to mirror the site to multiple servers, are there any hosting solutions for that?
Hi guys. I am having trouble loading a static css file. There are 3 of them for 3 separate pages 2 of them are working fine (home and signup) but the one for the signin page is loading an empty css file (when I see it through chrome dev console it's empty). I am not getting any errors so I am clueless why its happening. I am attesting the screenshots of necessary items below:
:ok_hand: applied mute to @thorny scaffold until 2020-07-03 12:39 (9 minutes and 59 seconds) (reason: duplicates rule: sent 4 duplicated messages in 10s).
!unmute 293915781211750400
:ok_hand: pardoned infraction mute for @thorny scaffold.
I will rename those files
try not to upload them too quick as well
Oh okay
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.
that link ^
Okay will paste settings.py's static section and both html and css files
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
'/var/www/static/',
]
{% load static %}
<html>
<head>
<meta meta name="viewport" content="width=device-width, user-scalable=no"/>
<title>JAEA - Create a new account</title>
<link rel="stylesheet" href="{% static "css/signup.css" %}">
</head>
<body>some stuff</body>
</html>
signup.html above
/* Montserrat google fonts */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap');
:root {}
.light {
--background-color: #f1f1f1;
--text-display1: #f1f1f1;
--text-display2: #2a2a2a;
--primary-color: #5229e4;
}
.dark {
--background-color: #383838;
--text-display1: #f1f1f1;
--text-display2: #f1f1f1;
--primary-color: #5229e4;
}
html, body {
margin: 0 !important;
padding: 0 !important;
}
body {
background: var(--background-color);
color: var(--primary-color);
font-family: "Montserrat", sans-serif;
}
a:active {
color: var(--primary-color);
-webkit-tap-highlight-color: rgba(82, 41, 228, 0.2);
}
.nav-link {
text-decoration: none;
color: var(--primary-color);
}
.brand {
text-align: center;
font-size: calc(0.05 * 100vh);
}
.brand-logo {
font-weight: 700;
}
.brand-text {
font-size: calc(0.04 * 100vh);
font-weight: 400;
}
.form {
text-align: center;
}
signup.css
{% load static %}
<html>
<head>
<meta meta name="viewport" content="width=device-width, user-scalable=no"/>
<title>JAEA - Sign in</title>
<link rel="stylesheet" href="{% static "css/signin.css" %}">
</head>
<body class="light">
some stuff
</body>
</html>
signin.html
/* Montserrat google fonts */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap');
:root {}
.light {
--background-color: #f1f1f1;
--text-display1: #f1f1f1;
--text-display2: #2a2a2a;
--primary-color: #5229e4;
}
.dark {
--background-color: #383838;
--text-display1: #f1f1f1;
--text-display2: #f1f1f1;
--primary-color: #5229e4;
}
html, body {
margin: 0 !important;
padding: 0 !important;
}
body {
background: var(--background-color);
color: var(--primary-color);
font-family: "Montserrat", sans-serif;
}
a:active {
color: var(--primary-color);
-webkit-tap-highlight-color: rgba(82, 41, 228, 0.2);
}
.nav-link {
text-decoration: none;
color: var(--primary-color);
}
.brand {
text-align: center;
font-size: calc(0.05 * 100vh);
}
.brand-logo {
font-weight: 700;
}
.brand-text {
font-size: calc(0.04 * 100vh);
font-weight: 400;
}
.form {
text-align: center;
}
signin.css
file structure
signup.css working fine
signin.css empty
Okay I fixed it by opening the css file in a separate tab
Seems like a Chrome problem
I haven't read your problem at all. But if you're newish to web dev, always consider that the problem might be caused by cacheing somewhere. Simplest is the browser cacheing files locally, and that can be fixed with ctrl+f5 or ctrl+shift+r
do I always have to create a django app if I want to make a site?
I want my site to be a one page site btw
ah wait, can I just set the path to / to make my app the first page that's loaded?
if its a one page site why use django?
Django would be almost pointless to use for a single page
Django's ORM is pretty nifty, if you want the ORM+Auth, then I'd say Django is worth it for one page
Django would end up being bigger than the page itself lol
I don't really know what that means
it just has a lot of overhead for a single html page
trying to learn django that's why Im using it
Well, anything with auth+database is a lot of overhead for a single page
plus I wouldnt use flask for a one page website that lets people post anonymous messages on the front page in a sticky note layout
django's orm is nice for all of that stuff
hey how do i get my text over image? im using pycharm
Does anyone know if there's a free way to host a website (that's not static) other than hosting it off my computer?
Most clouders offer a free tier or some initial credits, but that won't last forever
Ah I see
I think i have some free google cloud credits, so I should be able to make that work temporarily
If it's relatively basic, do you reckon $50 of credit could last me a year?
I know that wasn't super descriptive
but all I want to do is have the user upload some images
who can help me understand some oauth2 sutff?
hi i have a general question about flask forms
is wtf still the widely accepted way to do forms in flask?
@glad topaz what specifically do you need help with?
@wooden path you should take a look at AWS, depending on your needs you can pretty much serve your website for pennies
they offer micro EC2 servers for free, s3 buckets for free up to a certain gb
you should be able to work out what you need
@dark hare thanks, will check it out!
anyone here can help with a django-security problem?
or is there a better place to type?
i do
im not sure if this is classed as web developement:
I want to access my Nitrado Account via aioHttp. As I add the basic auth it only responds with the home page. Nothing else
@native tide thats HTML talk
add padding to them
ok
what is your problem exactly?
i've got a dynamicly generating settings file based on an environment variable that i can swap from debug to production
when i'm in debug i can use an <a download tag>
in prod it fails
the difference is in django security settings i have on the prod settings file
SECURE_SSL_REDIRECT = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_HSTS_SECONDS = 3600
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_BROWSER_XSS_FILTER = True
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_FRAME_DENY = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
i put them on because a friend said he had them on his
(not great i know)
not sure which one is the cause though
im confused as to what your exact problem is, how do you know this is a security problem? as you're telling me its a tag
<a href"path to file" download> --> works without above settings, fails with them
thats very very strange, are you hardcoding the path?
no
im assuming your looking in static files and you have set your STATIC_ROOT in your prod settings?
and STATIC_URL
what is your path, and where is the file stored
it all works without these specific settings like i say
so firstly
i would question as to why you are using all of these extra security settings when u dont know what they are doing
oh and debug = true
yeah valid question
just a recommendation from a friend who i'm trying to get in touch with to ask
does it work with debug = false and without those extra settings?
haven't tested that one
try it
no problem, cheers for your help
i would say theres a difference between your local settings and production settings
but I couldnt go further than that without look myself
👍
yeah i just turn debug to false on my local settings and get the failure so its that
at least have the right aim now
think this will help
@crude swan https://stackoverflow.com/questions/42861326/djangowhen-debug-false-media-url-returns-not-found
when DEBUG=TRUE,media_url is working,but DEBUG = False ,returns not working.
This is my setting file.
DEBUG = False
...
MEDIA_URL = "/pics/"
MEDIA_ROOT = BASE_DIR
urls.py
urlpatterns...
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)```
i already had that at the bottom of my urls.py
which i believe is the equivalent
using something like nginx was always a potential but didn't think it was a necessity
if you're code is the same as what the django docs are showing im very confused
i'll have a better look and come back to you if i get it
whats in your allowed_hosts?
https://www.youtube.com/watch?v=QC2cLkHoXLk
https://stackoverflow.com/questions/10664244/django-how-to-manage-development-and-production-settings
Setting up Django media files for development is about understanding what MEDIA_URL is and MEDIA_ROOT.
MEDIA_URL is simply a URL prefix (or "slug") that tells Django what the URL should look like when accessing media files from the MEDIA_ROOT.
For example, if you wanted your...
think you might need to check your allowed hosts aswell
Hello, I am very new to the web, I have an error 404 when I do with the flask.
That is my code , thanks in advance
I don't know why it will shows 404 when do flask run, but I do with the http-server, it will link to the page
Cart['bag'][name] = {data}
if "Cart" in session:
session["Cart"]['bag'][name] = {data}
else:
session["Cart"] = Cart
print(session)
whenever I have more than two items in session['cart'] only the first item saves, not the other items inside it
This is Flask btw
hello all
so my frontend dev is sending an image file in multipart/form-data. but there is some sort of fakepath error. I am using flask for the backend. Now I was simply using file.save(dest) to save the image file. But seems like his only options are sending the image file as a base64 or blob. I don't know how to handle those types of data. Can you help me?
the code works fine when tested from Postman/Insomnia. I'd assume the fakepath error is a brower security thing.
f = request.files['image']
fname = secure_filename(f.filename)
f.save(fname)
this was my code ^
you can't really
it depends a lot on the technology you're using
but the closest thing to that, at a high level, is AJAX
i thought to make bl;ack jack game
and in flask to get how many rounds he won
what u think how that could be solved?
gonna ask again lol since i didn't get an answer before:
what's the best way to make a form in flask? is it still using wtf?
I am using flask form for login system
but for registrating i am using normal input field
wym flask form?
probably WTFforms
@somber wedge
so my frontend dev is sending an image file in
multipart/form-data. but there is some sort of fakepath error. I am using flask for the backend. Now I was simply usingfile.save(dest)to save the image file. But seems like his only options are sending the image file as abase64orblob. I don't know how to handle those types of data. Can you help me?
@somber wedge we need more info
You can save/compress the images in the filesystem, store the path in a database.
a lot of the questions here can be solved with django lol, but @fickle fox If I were you, I would code the form in html
maybe flask has a form module
Flask does have a form section, tho html forms isnt very hard todo
tho i am just thinking of nice project to do in flask
something that will be nice to put in repo on github
if anyone in here have idea ping me xD
does anyone know what's one of the best django tutorials on udemy?
all the youtube tutorials really suck imo
tbh
only YT tutorial i would really recommend is Corey's Schafer
https://www.youtube.com/watch?v=UmljXZIypDc&list=PL-osiE80TeTtoQCKZ03TU5fNfx2UY6U4p#]
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...
as for Udemy courses im not sure
if you want more of a blog style one or one which isnt a video check out Django's own written tutorial which walks you through making your own polls app
Thanks alot
Hey All,
I have a flask app that I am developing and want to incorporate a custom data structure for each user that is unique and will constantly change based on the routes that are accessed. Without being to vague lets say I want to create a shopping list, you can add items to the list and delete items from the list depending on the route selected. How do I declare the shopping list while also making it unique to every user. I hope this makes sense I am not a web dev person and this is for my capstone so any help would be greatly appreciated.
Thanks
I had a doubt, can I make a semi-decent webpage in pycharm using the html script?
@prisma tree so you basically have some state for each customer, and you have a class that you want to instantiate separately for each customer with their state?
Using your shopping list as an example;
You can either have the html document have an empty shopping list, and a separate api that returns the contents of the list for a specific user - and using JavaScript in the webpage u query that api to fill the shopping list on the client side
Or you can have a template you fill out server side
Flask supports both. Templates: https://flask.palletsprojects.com/en/1.1.x/tutorial/templates/
I’ve been making a web app with django and I’ve come across a road block. How can I make it so each user I have see only what they add to the home page? Or give any user their own home page that they could add to and not change anything for any other user
For example, one user can add reservations to their reservation home page to display them. Is it possible for me to make it so another user can be logged in and add reservations and only see theirs that were added/have their own home page? Thanks!
@nova escarp You need an ACL system to do it properly (Access Control List). Do some research on Django ACL and you'll find some good tutorials.
ACL is for access right? How would I make a different “homepage” for each user? If I’m understanding correctly I give them their own homepage and I’ve ACL to only allow them to use it?
thanks for the reply @native tide
I wanna do the following, but don't know a way to go about it;
Have a pyqt5 GUI, with a web browser (with a local html file loaded). And I'd like a button on the webpage to call a python function, which will then update some content on the html page.
I'm using QWebEngine & PyQt5 by the way
Feel free to @ me
Anyone know a good resource where I can learn to webscrape dynamic websites like amazon?
I'm getting "TooManyRedirects: Exceeded 30 redirects." from requests. anybody know how to find out what it redirecting to?
hi everyone, im currently learning how to create rest api with django, and i want to store a list of items. For example:
i have Model called user, his attributes are name,age, height, weight, and so on...
for name i use CharField, for age i use IntegerField and so on. but i want to have an attribute with a list type, but there is no ListField or anything similiar. How should I do it? Sorry for bad English and thanks for the help!
@bitter wigeon Check out https://www.django-rest-framework.org/
Django, API, REST, Home
@bitter wigeon Check out https://www.django-rest-framework.org/
@quick cargo it doesn't specify fields, so does it work like python where i just declare an attribute and it detects the type automatically?
Django, API, REST, Home
It should automatically serialise any Orm objects from Django onto relevant data
as part of its Serialize Classes
hey anyone know why my godady domain cant be connected to heroku?
are you paying for your heroku dyno?
what specific issue are you having?
ah, that's why
this is on the domain
you told heroku you're going to point "absolutagents.com" to the app but you've pointed "www.absolutagents.com" to the app instead
you can use www if you want, but you need to tell heroku that's what it'll be
or you can change the hostname in godaddy to @ instead of www
I would suggest making sure both "yourdomain.com" and "www.yourdomain.com" can resolve as valid domains and just redirect one to the other
okay i've added a new domain on heroku with www in it
hmm okay
how would i go about that
on the dns settings
or just added both domains
mate
you're a champ
cheers
you can't have one domain redirect to another from just the domain settings, you have to control that either in your python app code or with something like nginx
cheers 🍻
eh, I'll say you usually can't do it from domain settings, some domain providers do offer that functionality
i tried to manually delete a User that i register through the website; i dont understand whats happening
im very new to web dev so please be patient with me, thanks in advance
ah yes
This is Django's most infamous issue
I would help with it but when ever that happens i end up remaking the entire project because migrations and everything get thrown out of wack
its really frustrating; i might end up doing the same. ive been stuck the whole morning on this one
honestly its quicker to just back the code up
and remake the project
the error altho rare if you get it you will be there for ages trying to fix it
the ORM isnt exactly very 'forgiving' when something goes wrong
ill do that, thanks a lot 😄
update: fixed!!, my silly self forgot to make the migrations.
Try
<img src="yourimage.test" alt="What is your image about" align="right">
In your html
Hello Guys,
Is there any way to get the response code from selenium or do i really need to first get website with Request and the load the page with Selenium, That just seems like a lot of request in a crawler...
Any advice? 🙂
Kind regards
i dont think u can
@worn aurora I think there is a way that whould be better than using both Request and Selenium, i dont whant to break website 🙂
what would that be ??
u can try to analyse the rendered html
@worn aurora
I dont now i just think that if take a website like Ahrefs, Semrush i really dont think they whould do it like this, but at the same time i really dont now 🙂
Do u know if there are any Python channels on discord about crawling?
update: fixed!!, my silly self forgot to make the migrations.
lol, that would've been my first guess
How to get visitor's public ip address in flask?
hey could somebody help me here i dont understand
I'm trying to redirect to /register html <p><a href="{% url 'register' %}">Register account here</a></p>
but Django says register is not a valid url or function when it is
I have py path('register/', views.register, name='register'), in my urlpatterns
<a, where is '>'
@late stone yo, do you have model called hr_department_hruser?
models are blueprints for database tables. If you have created a new model in the code you need to makemigrations and make sure you have migrated to the database
i.e. creating a hruser model and then migrating and creating a table in the database called the same
so when django tries to look for a hruser it will find the corresponding user in the database
from all of the answers that i can see you reference the name path('register/', views.register, name='register') and that's what I'm doing and it cannot be found. Please correct me if thats not the correct way to do it
i am just confused
have you done the official django poll tutorial?
yeah i did ages ago
ohh i got it
i just looked back at that and saw they used app:name
so i just used html <p><a href="{% url 'main:register' %}">Register account here</a></p>
👍
thank you josh, i totally forgot about migrating once you create model or change anything on a model. I was able to fix it
hi guys, can anyone help me with CORS problem :/?
from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Did you set the CORS header server side?
Ah, I have no AWS experience.
well it's a problem when making a request using AJAX
I'm trying to make the user make the request with 0 success
Does the request look okay?
If I do it manually in the browser
or in CURL
it works perfect and I get a response
The error seems to be related to loading a page as file:///
And permissions being very strict in browsers for the local filesystem.
What is the value of your 'Access-Control-Allow-Origin' btw?
'*'
eh, yeh I just added it to the server
getting a different error meh
has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
are you calling lambda functions straight from javascript?
any clue as to why a gradient wouldnt be showing up in django? all of my other styling is working just fine but my background ( which is set as a gradient) isnt working. It worked before when it was just a plain html doc
can you show the css? what's the page look like instead? a single color? which browser?
chrome, the page is instead just white
body{
margin: 0;
padding: 0;
background: linear-gradient(90deg, rgba(131,58,180,1) 0%, rgba(253,29,29,1) 50%, rgba(252,176,69,1) 100%);
background-size: cover;
background-position: center;
font-family: sans-serif;
}
.loginbox{
width: 320px;
height: 360px;
background: #000;
color: #fff;
top: 50%;
left: 50%;
position: absolute;
transform: translate(-50%,-50%);
box-sizing: border-box;
padding: 70px 30px;
}
h1{
margin: 0;
padding: 0 0 20px;
text-align: center;
font-size: 22px;
}
.loginbox p{
margin: 0;
padding: 0;
font-weight: bold;
}
.loginbox input{
width: 100%;
margin-bottom: 20px;
}
.loginbox input[type="text"], input[type="password"]
{
border: none;
border-bottom: 1px solid #fff;
background: transparent;
outline: none;
height: 40px;
color: #fff;
font-size: 16px;
}
.loginbox input[type="submit"]
{
border: none;
outline: none;
height: 40px;
background-image: linear-gradient(to right, #e52d27 0%, #b31217 51%, #e52d27 100%);
color: #fff;
font-size: 18px;
border-radius: 20px;
}
.loginbox input[type="submit"]:hover
{
cursor: pointer;
background-position: right center;
color: #000;
}
.loginbox a{
text-decoration: none;
font-size: 12px;
line-height: 20px;
color: darkgrey;
}
.loginbox a:hover
{
color: #ffc107;
}
the gradient was moved
into the html just to check if it would work
does it?
is this what you're expecting to see?
no, the button gradient works just fine, but the background does not
but yes that is the gradient
i was expecting
this is what i see
can you inspect the page and confirm the CSS rule is loaded on the page and the selector for the rule is correctly selecting the background?
im relatively new to web development as a whole, but i assume you mean whether it shows up in the chrome inspect?
yes, if you chrome inspect the "body" element, which CSS rules are being applied to it?
ok, and is the body definitely the thing in the background? as in, there's no element with a white background covering the entire page (behind the login box)?
no there isnt
if you "hover" over the body element does it display blue over the entire page? when you do absolute or fixed positioning, it doesn't change the size of the parent
example from something I'm working on where the nave is "fixed" positioning
although the "top nav" is technically a child of the body, it's outside of it
so its background wouldn't show up
for some reason my body is 801px by 0 ?
ah, you positioned the children with absolute positioning so the body has no content it needs to widen itself to support
im just confused as this worked before
add width: 100vw; to body styles
even with that my body still has no width
this suggests body {min-width: fit-content; } https://stackoverflow.com/a/57860826/8015233
for some reason it seems the user agent stylesheet is blocking my bodies css
also, if i didnt say this before, it will show any other color i set it too, except for gradient
s
well whatever, ill just have it set as white, not like it looks particurlarly bad. Thanks for trying to help me.
Objective: You need to create Test cases for trasaction management module.
1. Create Unit testcases
2. Integration testing for flow test for success and failed scenario. Assumption: Consider any Payment gateway like Razorpay or paytm and mock their responses for Success or failure.
Deploy your project on Heroku and give the demo by running the test cases. Process: 1. Create app with name "payment" .
2. Create model TxnDetail inside app payment 3. Create service file for accessing the Razorpay.```
Can someone help me by listening topics that I should learn to do this assignment. I've never usesed any payments gateway
Flask/Jinja2: Is it a bad idea to pass functions to render_template as args? (return render_template('compare.html', func1=func1, func2=func2)
I find it's making my life easier when displaying data from many templates into one.
I do end up with some logic in the html files (to decide what pages get included via {% include %} which am trying to minimize.
ok, I'll try that and see if it makes more sense. The main issue I had that led me toward this path was the number of variables needed in my main 'meta' page to include and re-use tons of chart.js graphs that are defined separately in other templates.
Can anyone help me with the above project. I can't understand what I have to do.
how can i show only some images in my database on a page and automatically create links for pages with their continuation so that i can navigate through them using buttons
using django
im pretty new to web dev so dont know what doing this is called
so heres a example of what i am trying to do
https://imgur.com/xw2B2cp
@upbeat flax so you want to be able to make images buttons?
no like i want to change the images shown when button is clicked
add that functionality
to button
like if my db has 100
i want to show 20 on different pages
and navigate using buttons
you would want to want to use want to use jinja2, which I think might come with django, but not totally sure
it lets you write code on the webpage
python code
then you would want to use for loops
to iterate through a certain amount of images you want displayed
for example, if you have images stored in a dictionary you could do:
{% for key, value in images.items() %}
<img src="{{ value[imgSrc] }}">
{% endfor %}
oh shit i get get it . all i needed was using loop for certain amount of them. thanks a lot
your welcome, glad I could help :)
Django doesnt use jinja2 but it has its own template engine
both are pretty similar and neat
How do I connect my python backend web app to the user's session or local storage?
Hey guys, i'm new to Django and figured out that Django has it's own default ORM (DjangoORM) for interacting with databases. Now, i was wondering if Django allows us to use an other python ORM library in it like SQLalchemy?
why would you want to use sqlalchemy though, djangos orm is so much easier to use imo
why would you want to use sqlalchemy though, djangos orm is so much easier to use imo
@ruby fjord Yes, i'm aware of that but i was wondering if there are any pros/cons of learning DjangoORM over SQLalchemy or any other ORM
Basically, i want to start learning ORMs with something that doesn't feel like 'cheating'
well DjangoOrm is appropriate for Django, if you want to make desktop applications with pyqt5 or something, I would go for Sqlalchemy
they each have their use though
plus nowhere in the django docs do I see anything about sqlalchemy just use Djangoorm for django projects, its super easy to use
they each have their use though
alright, i see it'd be better to just start with it already. Just needed a push in this direction. Also, i hope that it won't be that difficult to shift to working with some other ORM in future?
documentations are friendly
figured out how to use django orm in less than 5 minutes
ended up making an app that calculates how long you've been in quarantine, with no prior django knowledge
and was able to implement a web feed in an hour
hahah, interesting!
Is there a way to make the text from a python console appear on an html webpage? I need it to be able to support system clear if possible
im pretty new to coding
I guess what im really asking is can django/flask just substitute the console?
that's a weird way of putting it, but yes
though with flask and related, you're not outputting to console any more, and the console is really only used as a way to look at some logs. everything is happening between the program and the connected HTTP connection (from the browser)
that could be better than i expected thanks
Which is better for a simple program and a beginner?
Hello I am stuck hopefully someone can give direction. Has anyone encountered the error belos
NoReverseMatch at /edit/Apple
Reverse for 'edit' with arguments '('',)' not found. 1 pattern(s) tried: ['edit/(?P<title>[^/]+)$']
Alchemist, Flask is good, it's nice and simple
(Django)
What's the best name for the authentication app
right now I've named it authentication. But should I change it?
how would Initialize form fields with data from a text file'
Hi guys, question about django custom models, im using this example in the django doc https://docs.djangoproject.com/en/3.0/topics/auth/customizing/#a-full-example,
the thing is, is obligatory to modify the admin? if yes, it needs to have the same fields as user?
Hey guys
So I have a web server with multisites hosted using Apache virtualhosts
If you go to sub1.tld.com you go to /var/www/sub1 and so on
when I go to the public IP of my server, why am I being particularly redirected to sub7? Any way to change this?
Kindly @ping me if responding, I dont get notifs otherwise
@fast charm you don't have to really modify the admin
but like, if you want to be able to change things posted by the user models, you need to add those models to the admin file
As a complete noob to both frameworks, could anyone tell me how long it would take me to build a habit tracking app from scratch using flask/django?
for some reason I am having a lot of trouble when I try to store python dictionaries in flask session, for session storage, which is a dictionary itself. I can do;
session = {dict1: {dictA: {dict1: {data}}, dictB: {data}}
It depends @whole oracle
What knowledge do you have in python ? How fast do you learn ? Do you know how "the web" works ?
Has someone worked with pythonanywhere before ? can someone help me here everything works fine but localization not working on the server but it works on the local host when i try to change from english to arabic the text doesn't translate can someone please help me
but when I store more than one dict in the 2nd dict1 like this:
session = {dict1: {dictA: {dict1: {data}, dict2: {data}}, dictB: {data}}
When I print session in that function or url, it prints both, dict1 and dict2 inside it, but when I switch to a different url or function it doesnt save
@bleak bobcat I have quite a bit of experience with webscraping (if that counts as knowing how the web works), and I'd say I'm an intermediate level in python in general
I learn pretty quickly as well
Then it shouldn't take very long, a few hours/days
Does os.chdir and url_for not work together?
In my views.py, I need to access CSV files stored inside my static folder but it doesn’t work
How do I add data to clients web browser's local or session storage, I am using flask if that helps, but Flask session is having problems with dictionaries, so I need another way.
I need help with this. I am using the ObservableAnalyzer class at various places, and importing it from parent directory. It's the same error at all places in the code. Directory tree:
script_analyzers/
- observable_analyzers/ - I have like 30 files inside which imports the `ObservableAnalyzer` class
- classes.py - contains `ObservableAnalyzer` class
and codefactor is giving me this error:
i just found out pycharm doesn't support CSS unless you upgrade the IDE to a paid plan.
that seems ridiculous and can't be accurate
is this true?
try vscode @swift sky
so it is true then, what kind of garbage is that
Pycharm is for editing python not html/css. Kind of in the name. I don't think it's unreasonable of jb to want to make money
Its a community edition, people are allowed to make stuff themselves
is anyone familiar enough with django that they could help me with one of my problems?
same^
same^
Maim^
I have a question about flask
I want to redirect from one view to another but I can’t just use redirect(url_for()) because I need to pass a variable from the first page into render_template() in the second page
@barren phoenix feel free to hit me up as well, python/Django is my day job
@native tide I'm struggling with coming up with ways to optimize my querying in Django - do you have some time to look at the 6 lines of code I have?
sure, toss it my way and i'll take a peek here soon
serialized_last_object = FarmDataSerializer(last_object).data
last_timestamp = datetime.datetime.strptime(serialized_last_object['timestamp'], '%Y-%m-%dT%H:%M:%S.%fZ')
# last timestamp - 24 hours
time_24_hours_ago = last_timestamp - datetime.timedelta(days=1)
# query farm data for the last 24 hours for farm_device_id 01 - 16
farm_device = FarmData.objects.filter(farm_device_id__gte = 1, farm_device_id__lte = 16, timestamp__gte = time_24_hours_ago).order_by('-timestamp')
serialized_farm_data = FarmDataSerializer(farm_device, many=True).data
My code works however even after going through the queryset documentation I am not sure if my code is efficient. I am first getting the latest timestamp, finding the timestamp that is 24 hours before and running a new query. I am using postgresql for my DB and the data is being updated every minute. This function is called when the page refreshes. So Since the latest data uploaded is what I need, would there be improvements I can do to this code, as the database grows the runtime would also increase with my current code?
I'm currently in the general voice chat feel free to hop in @native tide
FarmData.objects.filter(...)[:2000]
just trying to get a little more clear about what you're looking for before i dive in, but
query farm data for the last 24 hours for farm_device_id 01 - 16
is this actually what you want? because the code is getting the farm data from 24 hours before the last timestamp for whichever single device ID had the latest timestamp (not necessarily 24 hours worth from any other ID afaik)
yes @native tide
time(db_index=True)
you may be able to annotate the max timestamp, then use an F query
but honestly i think i'd probably have done basically what you're doing
i wouldn't think you'd need all of the intermediary serialization though
also agree with chimp, would be good to use values/values_list, db index if this is gonna be pretty core or really slow otherwise
Got it, @native tide thank you so much
np!
Hello, it's better to start with Flask than Django as a Python beginner?
yes, Flask is a smaller library and relatively simple to work with
thank you ;)
anybody getting this error of "import error: cannot import 'secure_filename' from 'werkzeug' while using flask_uploads??
@native tide yeah i did that but still had the issue
but no worries i already solved the issue. the bug was related to the current version of Werkzeug . so i downgrade to the prev version now everything is working 💥
Could anyone help me real quick with a python script, I have this result url, I want to to return the Q/A https://quizlet.com/115692525/geology-ch-1-4-flash-cards/
@safe glen glad to hear that 😄
In multi-table inheritance, why the child class doesn't inherit Meta class from its parent Meta class?
How do you send multiple files using xhr/ajax and receive them as Image objects lets say in python?
Is Django related code questions ok to ask here?
Did not see that. Thanks.
I'm not able to display the profile picture of my users. I have followed the Django docs
In the project folder under settings.py I have
MEDIA_URL = "/media/"```
and in the urls.py
```from django.conf.urls.static import static
from users import views as user_views
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)```
Not getting any errors when running the enviroment so i don't get the problem
What do you get when you inspect that image src ?
Unknown source
<img class="rounded-circle account-img" src="{{user.profile.img.url}}">
But src will show as unknown in chrome
And what's your model ?
from django.contrib.auth.models import User
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
image = models.ImageField(default="default.jpg", upload_to="profile_pics")
def __str__(self):
return f"{self.user.username} Profile"
So if user doesn't upload his image of choice, it will resort to the default.jpg image
Any here have experience with fastapi? I'm looking to return multiple data obtained from another source within a JSON format. Am I better off creating a json object with the keys needed, populating within a for loop and returning this? Or is there a better way within fastapi? Example of how I want this structured when its returned:
"users": [
{
"id": 1,
"first_name": "Robert",
},
{
"id": 2,
"first_name": "Lucy",
}
]
}```
So for loop it
Don’t put too much thought into it, application will spend more time in database then building.
Hello community , anyone got an error with email validation with flask > when I use an email with a dot “test.first@exemple.com” the registration form doesn’t work as it says to that it’s not a valid email ?
Flask email is very janky. The most popular package for it hasn't been updated in a long time
best system is make a custom form in html with a regex expression to check
Oh. I'm completely misunderstanding. I thought it was about email verification
django forms tho
there's a "standard" regex expression out there that checks for email format
Okey I ll check tonight
there's a whole site dedicated to it: https://emailregex.com/
Almost perfect email address regular expression. Just copy and paste for a language of your choice. Feel free to contribute!
although the Python one in there is the simplified one, it'll probably work for what you need, though the more complex one is more accurate, I'm not 100% sure it's formatted correctly for python. feel free to try it
this one:
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])
versus this one
^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$
one of the two probably
hey is someone is familiar with Django signals, can you explain why do we need it at all?
You don't need it. In most common websites you're not gonna use them
@twilit zenith if it’s when you are creating a profile or notifying a set of receivers then think about it as a trigger
im using Django rest framework and Vue JS cli
I learned how to create API and stuff but I'm a bit confused cuz some people used signals
some are using rest_framework router
idk what to do gotta do more research I suppose
I think router isn't needed, but I'll most likely use signals for post notifications
I can use Vue router plugin anyways
can I simply run a django2 (not async) style app from the asgi entry point
Heya!
If I create a ForeignKey field in my model that points to the user(s) table, and I get every value from this model and render it with a html, what is the default value that I get if I try to access model.user, and why?
Oh, yes that's django.
hi guys a beginer question for my first fullstack app. Not sure if using express vs flask is better for a multipage app. The main drawback I see in flask is it's not asynchronous. So would that mean express is better?
a little hard to compare. use whichever you are more comfortable with - python or javascript
anyone have a tutorial on how to setup a venv for Django
I've been trying to do it for hours and I still somehow haven't done it lol
you need to use <a href="The link for the video">https://roblox.com</a>
I do but if I copy the link and then paste it here, it shows the actual link
when you copy the link of course it will post it as the youtube link on discord, because you're copying the source
you can't
<a href="https://www.roblox.com ">https://youtube.com</a>
alright
<!DOCTYPE html>
<html>
<body>
<h1>The a href attribute</h1>
<a href="https://www.roblox.com/ ">https://youtube.com/</a>
</body>
</html>
thats my current code
what do I do/
😓
?
<!DOCTYPE html>
<html>
<body>
<h1>The a href attribute</h1>
<a href="https://www.roblox.com/ ">https://youtube.com/</a>
</body>
</html>
so will that work?
not for what you want to do

