#web-development
2 messages · Page 130 of 1
@left kraken did some debugging
I can't execute it in the directory, but if I move the file somewhere else it works
no idea what could cause it
You can use blueprints to speed up devel of a app, also equip yourself with extra schema validator
XSD
I had socketserver.py in the same directory
and it interfered for some reason
Glad to hear that you fixed this issue
If I do this, the code works, if I make it so the interpreter doesnt shit itself it doesnt
oh, I had to mark the directory as source
cuz in django it creates a project in the project
and uses the second project file as the source file
Hello again, is there a way to show a pdf inline response inside an html template? Like inside a <div>
ye hi
Bro u know flask?
yes?
What things we should cover using flask?
Is JS highly required or little bit is okay for web development?
hey guys, so I made a chatbot using tensorflow and tflearn in python.. it works but as a stand alone app. i wanted to make a django website and add the chatbot in it... could someone please list resources i can look at (it’s my first time doing this and I don’t know what to even search for)
p.s. I know django.. I just wanna know how to integrate the chatbot into the website
I mean you really dont need much JS todo stuff
JS is useful to know if you wanna do certain interactions
but overall no its not massively needed
Could someone help me with me not being able to find my html template?
Probably more of a JS question, but here goes: does anyone know the best way to handle the soft keyboard on Android? The resize event triggered by focusing on input elements is messing up my contact form layout. The method of seeing if only the height changes I've seen on some blogs does not seem like a tenable solution. Any help is appreciated. Thanks in advance.
If you want to do front-end stuff, you should know JS.
You can build a website without any JavaScript, but almost all modern web UIs use some JavaScript.
Ok
Does anyone know how I can set environmental variables in nginx, the default export NAME=VALUE in Linux does not seem to be working and I am having an issue with flask as it is not reading them
For anyone curious, I figured out how to deal with the soft keyboard deployment on Android, which seems to work fine. Here is the code (JavaScript):
// Function to determine whether soft keyboard has been deployed
function isSoftKeyboardResize() {
// Only applicable to touchscreen devices
if ( 'ontouchstart' in document.documentElement ) {
if ( window.innerHeight < preResizeWindowHeight && window.innerWidth == preResizeWindowWidth ) {
isSoftKeyboard = true;
return true;
}
else if ( window.innerHeight > preResizeWindowHeight && window.innerWidth == preResizeWindowWidth ) {
isSoftKeyboard = false;
return true;
}
}
// Return false if not a touchscreen device or orientation change
return false;
}
// Change formatting if soft keyboard resize
function softKeyboardReformat() {
if ( isSoftKeyboard ) {
body.style.height = preResizeWindowHeight + 'px';
}
else {
body.style.height = null;
}
}
// Functions to run on resize of window
window.addEventListener('resize', () => {
if ( !isSoftKeyboardResize() ) {
// Resize functions to run under normal resize circumstances
}
else {
softKeyboardReformat();
}
preResizeWindowHeight = window.innerHeight;
preResizeWindowWidth = window.innerWidth;
});
I imported pillow (PIL), but when I do “from PIL import image”, it doesn’t work, there is an error, why!
Image should be capitalized
Does anyone know why transitioning position (left, top, etc... ) and transform for absolutely positioned elements in Safari might be proving to be such a problem for me? I have an animation which works very smoothly on everything but all iOS browsers and Safari on MacOS (Chrome on MacOS seems to work fine).
What is the python3 equivalent of PHP's json_decode ?
json.loads?
What @native tide said. Not sure what json_decode does, as I don't know PHP, but that seems right. json.loads turns JSON into a Python dictionary. If you have json as a file, use json.load. Remember, you need to import json.
@topaz widget @native tide Thank you both.
Web pages are files.
But a functioning web page usually utilizes multiple files to run.
How do you query from id > 1 and id < 10 for instance in django
Model.objects.filter(pk__in=[2..9])
may be alternate attribute and height and width of n image
# importing necessary module
from flask import Flask
from flask import render_template
from flask import url_for
# pass the webapp throug "app" variable
app = Flask(__name__)
# default route
@app.route('/')
def index():
return render_template('index.html')
if __name__ == "__main__":
app.run(deubg=True)
I am trying to run this flask app but this error appear
flask.cli.NoAppException: Could not import "app".
@violet zealot can you copy the full traceback in here? Not just the last line
this maybe? https://stackoverflow.com/questions/37908358/flask-cli-cant-import-application-set-with-flask-app
ow thanks man
My file name is application.py
i set set FLASK_APP=app.py
that's a silly mistake 😄
how can I iterate through all django objects and change a value for them?
I need help with React.
I have this component called ListGyms that renders two child components (one each time depending on the state). This component routes to the main react page, and stays rendered regardless if the child components (either of them), gets rendered.
These 2 components are rendered from a click on a button that is a part of a ListGyms component. Now, what I need to do is pass id as prop to these 2 components, because I need it to render some data from the backend. I am not exactly sure how to accomplish my task.
I am using react-router-dom for routing.
Here is github gist that shows you the code for all my components.
https://gist.github.com/eonbre/10a6932a5fe471cb1d7c4398a1ef9b8b
Thank you in advance for any help or guidance.
model.objects.all() gets you a queryset which you can iterate
Which is best database to be used as a beginner in python?
sqlite
Bro can we use sqlite in flask
yep
Ok
How can we do that
I was wondering how it can be done?
I was actually learning flask and in that got a thing called sqlalchemy which is used as a database
I couldn't understand and just messed it
a small question from noob. why i need this dot before models when registering model in django?
Hi guys I'm hoping to start a new project soon which i will admit now is quite ambitious, i am planning to try and use chat logs combined with a machine learning algorithm to create a chatbot which will be able to sustain as good a conversation as I can get it to do. I want to use real chat so it learns true responses to questions. But i'm not sure if i should make it so right now it can only answers questions on one topic, like a specialist on python and i wondered if anyone had any experience and could offer me some advise on what's best to do as well as if anyone was able to give me some clips of chats i could use for this project? Thanks in advance guys!! 😁
Hey guys, I'm unable to use my db on my Django project...
django.db.utils.OperationalError: (1045, "Access denied for user 'root'@'cpc76456-belc9-2-0-cust5.2-1.cable.virginm.net' (using password: YES)")
I'm seeing this here when trying to launch the app, I can log into the DB, I'm connected to it using mysqlworkbench
You can go into the django source code and check out admin and see what it is, it's most likely a class and the dots would make sense.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'GorillaFitness',
'USER': 'root',
'PASSWORD': 'mypass',
'HOST': 'dbendpoint.blah',
'PORT': '3306',
'OPTIONS': {
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"
}
}
}
I've specified the db properly on my settings file as well, omitted the sensitive information
The actual database doesn't really matter, if you are using python you are most likely communicating SQL within a pythonic way, via an ORM. If you are using Flask, use Flask-SQLAlchemy if you are using Django it has its own inbuilt ORM. These ORMs are used irrespective of the database (sqlite, postgres, etc.)
Hello. I use flask framework and I have one small issue. CSS does not update properties of input, but p works just fine.
Here is code as an example.
p{
color: red;
}
input#sbar{
border: 4px solid black;
}
change it to #sbar
I tried that. Did not work.
is it an id or class assigned to the html field?
ID.
It's like black magic to me. I tried without flask framework and it worked without any problem.
I dunno if you specify the colour in the border
I mean you can since it is working outside of flask.
guys, how can i get json info to send with request.post? for example i need to log in insiede a website, how can i get the json (payload) to send?
Any advice?
I meant in Flask, it seems it's expecting differing syntax
shouldn't be though, I tested that quickly, and it does indeed work in that manner
Try using the dev tools on your browser
Yeah it works in dev tools.
It's like completely ignoring what I have inside the css #sbar.
I'm using Flask-Migrate to check for differences in my code. However, Alembic doesn't seem to detect anything after running python3 manage.py db upgrade after the following change is made:
username = db.Column(db.String())
⬇️
username = db.Column(db.String(), unique=True)
How can I get it to recognize a table with an updated column like this?
Thanks in advance!
Can't remember, but I think you need to configure static files (e.g. css) within flask
Ok. I have found the problem. It's something to do with the browser cache. As soon as I deleted browser cache CSS started to work. I just hope that I don't have to do this every time I make changes.
Static files are configured well otherwise properties in p wouldn't work either.
ahh control shift r every so oftne caching can an annoyance
Quick question to anyone that has deployed a django server
I have variables, code and other scripts that execute when the website runs as well as things outside of "views"
will this not work properly if i were to deploy?
like if two people were trying to run the same script?
are all actions, scripts and data suppose to be initiated through post/get requests?
Hii I have configured the django, gunicorn and nginx with the following tutorial of digital ocean using ubuntu os on digital ocean droplet. gunicorn and nginx both configuration are perfect but cant able to access the site on domain ip. Help is appreciated. https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04
Hey, this is related to my python project I am making: Does anyone know how to edit a json file within javascript not using the require function?
hey guys, I want to make a screen for my webpage that will show when the download is going on, can anybody help?
Is there a way I can host my own flask website with a custom domain custom.com and a secure https:// and all that good stuff a normal website should have? I know I will have to pay for hosting and domain and more, but is there a way to do this?
Thnks @native tide
Why don't u use a local host
But it won't provide https: type thing
Use xampp which provides sql database and allows hosting websites
Check out on google
@surreal horizon
hello
does anyone know how to add a page on wordpress where people can leave messages
with the free version
i dont know if this is the right channel to ask but I would aprreciate the help
does anyone know how to make point and vector classes
thanks ill check it out
.
I'm unable to connect to my mySQL db on AWS on my Django site, but I get this error:
django.db.utils.OperationalError: (1045, "Access denied for user 'root'@'redacted info' (using password: YES)")
I can access this DB using MySQLWorkBench with no issues whatsoever
~/dev/sdasys
├── instance
│ ├── dev.sqlite
│ └── prod.sqlite
├── LICENSE
├── Pipfile
├── Pipfile.lock
└── sdasysapp
├── app.py
└── __init__.py
~/dev/sdasys$ flask run
<< flask.cli.NoAppException: Could not import "sdasysapp". >>
wh
y
__init__.py:
def create_app():
app = Flask(__name__)
return app
sry for the cryptic "why" but i think the other things speak for themselves
i have a factory function where its supposed to be, im in the right directory to run flask run, FLASK_APP is set to sdasysapp as it should, what am i doing wrong?
Hi Guys, good evening
Anyone knows how to load in .html files as a subpage?
Im using this for main page:
import http.server
import socketserver
class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
if self.path == '/':
self.path = '/index.html'
return http.server.SimpleHTTPRequestHandler.do_GET(self)
handler_object = MyHttpRequestHandler
PORT = ***
my_server = socketserver.TCPServer(("", PORT), handler_object)
my_server.serve_forever()
Hi on Django project i've declare class from Generic.View and into my class I declare : uccess_url = reverse_lazy(home). home is a view in the same file view.py but it's not a class it's a def and juste return render : return render(request, 'planner/home.html') So that its ok it's working. but i don't need to return home page I need to return a List Page. My List page in view.py is not a def but is a class -> class ListPlanification(ListView): and if I write in ma first class view uccess_url = reverse_lazy(ListPlanification) don't working and return an error NoReverseMatch.
Someoen can give me track or idea for solve this issue ?
thx a lot per advance 😉
Hello. I was wondering if there's a popular web dev stack that uses Flask, or what technologies can I combine Flask with
Hi everyone I'm deploying a Django Blog App on heroku, when I have the settings file with DEDUG = True all seems to work properly but when I turn it to DEBUG = True I get a SE
SERVER ERROR 500
check your logs
I think that the error could have something related to media files, but I set the app to point the media files in a cloudinary account
can't tell what's wrong without logs
Give me a minute
2021-01-30T00:11:15.000000+00:00 app[api]: Build succeeded
2021-01-30T00:11:32.906071+00:00 app[web.1]: 10.41.153.135 - - [30/Jan/2021:00:11:32 +0000] "GET /blog/ HTTP/1.1" 500 145 "https://developerroad.herokuapp.com/projects/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36"
2021-01-30T00:11:32.906703+00:00 heroku[router]: at=info method=GET path="/blog/" host=developerroad.herokuapp.com request_id=289a75cc-8c81-4b15-b5b0-31046c58a7df fwd="181.53.13.106" dyno=web.1 connect=1ms service=602ms status=500 bytes=410 protocol=https
2021-01-30T00:11:33.549479+00:00 app[web.1]: 10.41.153.135 - - [30/Jan/2021:00:11:33 +0000] "GET /favicon.ico HTTP/1.1" 500 145 "https://developerroad.herokuapp.com/blog/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36"
2021-01-30T00:11:33.550239+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=developerroad.herokuapp.com request_id=dd5d5227-15e8-4398-abd2-65a741b862e5 fwd="181.53.13.106" dyno=web.1 connect=1ms service=28ms status=500 bytes=396 protocol=https
Here is the log of heroku
What free tool do people use to manage their python dependency vulnerabilities for their project? I already looked into Snyk
Is mysql on rds? Django on ec2? You ll need to specifically enable port 3306 for the secgrp the ec2 machine is on
I got it sorted but thank you! 🙂
I've a flask app, and I have a template thrown together; can it be exported to a pure html file? I require to attach this html file as part of my application Is this possible?
Does anyone want a FREE Portfolio made for them, as i am really bored atm
When Django Documents (like css/js) are sent to browser from the server , are they gzipped automatically ?
DO we have to setup a cache policy for the static files we are sending from the server side or is that done automatically
/
@rotund token DM
what's the correct way to log errors? I have a big app, and everything works, but of course stuff could break in the future. I have a lot of eventhandlers if it unexpectedly returns any 404, 500 etc. The only way I can fix is wrapping everything in try:except
anyone know another way ?
what is the difference between django and flask?
Hi, I need help with Flask-WTF. Specifically with special character escaping.
I as understand flask_wtf escapes all special charachters by default, but when I type special characters i my field and try to access them in my view it gives me unescaped data.
For example field:
class Form(FlaskForm):
title = StringField('Task', validators=[Required()])
then later when I enter value <script>malicious code</script> in html form and send it, I call
form = Form()
print(form.title.data)
and get the same unescaped value
<script>malicious code</script>
but what interesting is when I just print field itself it shows that value attribute is properly escaped
print(form.title)
gives me
<input id="title" name="title" required type="text" value="<script>some</script>">
how can I get escaped data?
Bro refer documentation of flask
It will be much helpful
@rotund token how to make a bot using python?
Using ML/AI or something else
@brisk spear Are you answering to my question or the one above?
Is there anyone knows if there's a request.form.getlist() or equal method in Quart?
Hello ! Question : I have 2 classes in my django.models : Products and Clients, I have my views and forms all set to add/edit/delete my entries. When I create a new client, I am able to SelectMultiple products ordered by him (M2M Field in Clients), however, I would like to do the same when I create a new product item, I would like to choose which client can order it via SelectMultiple as well. I am not sure how to call two Models in my views/forms, anyone?
you can set up a reverse relationship with the related_name attribute and then you can access your M2M field from both sides:
https://paulgrajewski.medium.com/django-reverse-relationship-e6b1939561e2
Working with Django ORM can be very handy. One of the many advantages of this solution is the reverse relationship.
Thanks, will try this !
Hello, I need help with Scrapy, I want to explain my problem via Video and screen sharing. Is anyone here can help me by any chance ? thanks in advance
Hey so I don't know if this goes in #web-development , but ;-;. So basically, is there a way to tell how many users are returning to your website using Cloudflare analytics? Because I only see Unique Visitors but not Returning Visitors in the Overview tab. Thank you in advance!
@solar spire I was giving up a suggestion so that something can work out
To your problem
Do you store Refresh Tokens in the clients browser?
I would like a couple people advice me in the following: I'm thinking in starting a new business and I need a e-commerce website, I have two options in mind: first keep it simple and use shopify and second: create the website myself cloning a actual system that works and making some modifications if needed according to the business.
You need to measure and weigh your costs/time/experience and then decide. Shopify gives you most of the stuff pre built. Doing it yourself would mean many hours of work to be put into it. And how many hours goes into it depends on your level of experience and the complexity of the project.
yo
<section class="home" style = "background: url({{ url_for('static', filename='/Thank You/{% background %}.png') }});">
will something like this work?
flask btw
can someone tell me why my fixed header is making my page unscrollable
are you sure youy <> is only in the header ?
i don't know the word in english sorry but what i means it was : your html basile which fix the header is only inside the header and not into the body too
at some point i changed my header from div to header tag but i didnt change the closing tag
thats why it broke
ok so the good word will be tag, cool i know a new translation word 😉 and happy to help you
how would you handle this situation
the user receives an email daily with updates about random work responsibilities
currently that data is being copy and pasted into a text area field in a form, and being stored in the db
and when rendered in the html its not keeping the format
it returns the data as just one large block of text
is it HTML that is stored in the db ?
or just regular text
im trying to make it so that the data is returned with font size and and whitespace
it's just regular text i believe
what do you mean by not keeping its format?
got an example?
font-size is done via css
maybe try variable|safe
if whitespace isn't being kept
try printing the variable in the back-end and see if it keeps the whitespace
one sec
but then how will it know how to differentiate titles or sections that need to be bolded
it's currently set as variable|safe
insert it as HTML into the database if you want to have headers etc
and will the db actually store the html by default?
no
you have to send the html to the db
if its a basic textarea, its not gonna be html by default
is flaskwebgui the best/easiest way for a simple UI to call my script ?
maybe use a WYSIWYG editor
it replaces the text editor with its own text editor, and it retuns pure HTML that you can store in the db
thats one I used last month
checkout tinymce
so the idea is the user uses this editor to write some stuff, and when they click update post it gets submitted to the db as html
yeah i think its best you use an editor like one above
I pushed my repo to github when i created mine, lemme try find for you
you made your own editor?
no, I used tinymce
basically you want to include the tinymce cdn
init tinemce
when the user clicks submit, grab the content of tinymce and assign the value to a hidden input field
in the backend get the value of input field
insert into database
im looking at your stuff now
and tinymce
uhhh
i dont use any of those webframeworks
how do you init tinemce
yah its the community edition
having some issues embedding into my current html file
what issue ?
just copy paste the code inside your script tag
and then change ID of your textarea
i was embedding it incorrectly because there was html already present
expose api key though?
what is all this in your github
selector: 'textarea',
block_formats: 'Paragraph=p; Header 1=h1; Header 2=h2; Header 3=h3',
plugins: 'advlist autolink lists link image charmap print preview hr anchor pagebreak codesample code spellchecker code',
toolbar_mode: 'floating',
codesample_languages: [
{text: 'HTML/XML', value: 'markup'},
{text: 'JavaScript', value: 'javascript'},
{text: 'CSS', value: 'css'},
{text: 'PHP', value: 'php'},
{text: 'Ruby', value: 'ruby'},
{text: 'Python', value: 'python'},
{text: 'Java', value: 'java'},
{text: 'C', value: 'c'},
{text: 'C#', value: 'csharp'},
{text: 'C++', value: 'cpp'}
],
toolbar: 'advlist codesample autolink lists link image charmap hr anchor preview pagebreak h1 h2 h3 p a code spellchecker blockquote'
});```
@mint palm youtube and documentation. Corey schafer has a good series
Ooh thnx, does he cover the entire topic?
hi guys, sorry i'm trying to search from older message about this issue but i cant understand the answer.
i'm trying to run django-admin runserver and got this error msg:
django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
I already had this in manage.py:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mySite.settings')
am I doin it right?
however if running using python manage.py runserver its working.
i'm just curious why django-admin not working.
Is it possible for django to set for example:
127.0.0.1:8000/example
To normal html without using any of the django properties?
wdym?
yes, but the django html thing is limited
I would recommend having django as the backend and then using
react at the front.
django is really powerful and will also help scale your application
Seo wise everything is client side rendered
no I didnt mean that django cannot render
you dont have the tools to do AJAX and stuff
thats the catch
browsers cannot run python
For SEO django is not the best choice imo
Because it loads and creates the HTML when is requested
so my solution is put everything Django on a subdirectory
? I didnt get you
Hey all
I have a doubt whether should we install flask again while creating a new project again ?
Also suppose I am using python3 so what happen if I install virtualenv? Will it work properly?
I mean that I wanted how to make a chat bot?
heey so i made a website with python and html there are pictures of my cats http://zeroiq2018.pythonanywhere.com
Bro are u beginner
in what
In html and python
well i have been coding python for 5 months now but in html and flask only a month now
Ok
Try to learn css and bootstrap
It will make your website attractive
Well then, good work
im not sure
<form action="/cats/" class="inline">
<button style="background-color: saddlebrown" class="float-left submit-button" >go to my cats</button>
</form>
no html
Ok thnks
no problem :D,
python
i know the syntax learned pygames,tkinter,flask,pyautogui,ursina,panda3d
yeah i use it for everything
Bro one advice
Why don't u use python 3 it has built in environment
venv
It might be easier right?
as said il try it out
Like other version
yeah my code for my website is on it
Bro have u got github Student developer pack?
no
Bro apply for it
what does that give i have a school email so i could apply for it
Are u in school
Which class?
8th
but i was able to get the jetbrains ide licenses
windows
no pycharm
Yes
can someone please help me here?
So I have made my own API using, Flask, FastAPI and I want to host it under api.domain.com, I have created an a record in the dns poitning to my unbuntu vps. But I'm quite unsure on what to do next
You would need to add the api onto the server
which u can do with ftp
and u need to install python on the vps
then you would go to the api directory and run pip install on the requirments file
Then u can use a process manager and run the api
Hi all, does anyone know of a Python library that outputs Javascript? Similar to how yattag outputs HTML?
I realize this is kind of an odd use case.
I have a Python script that synchronizes some data on the backend of my server hourly with a third party API, and I'd like to add functionality to this script to output some of the data as a file with a Javascript object.
i don't think there are suck library, but javascript use format type of JSON you can come up with some logics to handle what you want to a JSON format to write a JS file
guys how can I keep the left side options, the logo and the search bar in place and make the chatbox scroll up and down?
what should I do?
Hello who know very well DJANGO ?
anyone have any experience with file upload via webapp into flask ?
You would be looking at a static display type
the pink highlighted area is a static container
To make it so shit stays aligned properly i would also consider using a flex box to properly position the static stuff
otherwise it'll go a bit mental
flex + flex-column
hi i have a problem with my tcp chat room it works fine on a local network but i cant get it to run outside my network
can you help me
plss help in this... I am a begginer and new here... so cant access the voice ... plsss help me in this... and have to give a voice message coz... the problem was long to write
Hello people, is there anybody able to help me on this matter? https://stackoverflow.com/questions/65975468/how-to-create-update-manytomanyfield-related-models
can someone please help me with django-thumbnails here?
https://github.com/jazzband/sorl-thumbnail/issues/663
any help will mean a lot,
this issue is with me for a week now... 😢
[DJANGO] Is there a specific reason for a form to be put multiple times inside an HTML template?
I pass a ModelForm to the html template, but the template "prints" it like 6 times 😩
hello how would i remove these artifacts ?
testing
\r\n
\r\n
testing```
for example it's pulling the headers and stuff [{'content_id': 2042, 'the_date': '02-01-2021', 'content': '
and the line breaks
\r\n```
this is my view
sql_query2 = "SELECT content_id, date_format(load_date, '%m-%d-%Y') as the_date, content from roll_call order by content_id desc limit 5"
and
data2 = cursor.fetchall()
fragment2 = data2
The one thing I see that may be an issue is the indentation of the for loops here.
how do you create or make a website
Hello who know very well DJANGO ?
Hi, I build the tool lifecockpit.com. Can somebody help test it?
how can i check if the email adress and name already exists in the database. This codekeeps redirection me to the login
Bro u are using what database?
have you writen it in django?
Are you sure you can have two different views for the same URL?
I rebuilt a store I found online, with Flask if anyone fancies taking a look, see if I could change anything:
https://github.com/MrNaughtZero/uSell
Live Site: http://usell.store/
@brisk spear mysql
not sure, should it be a problem
You tell me. When you make a request see if both views are working for that URL. Personally, I think your error here is because you have assigned two views to the same URL. I'd try to put print statement in both views, visit the URL, and see which one runs.
The database shouldn't matter too much, it's still SQL, it's not database specific
Ok
ok ty bro will test it
@wanton ridge can u suggest some channel/website where it is well explained
codeacademy@brisk spear
Ohk thnks
no problem
Maybe check all the entires with a loop, might be slow though.
Loop through the usernames in the database checking if there are matching
if match return a message and blah blah blah etc
That's the only method I can think of
how do you create a URL?
i have a guess, the method get has to be in ('email') not ['email'] this is a post method.
did you check this?
yes both are running
well in this case, when the user signs up they will always be redirected to login when the Password == Confirm...
You need to add another if/else statement checking if the email is available. If it is, sign them up, if not, show them an error message.
It would help to keep it within one function. Also, why don't you use Flask-SQLAlchemy? They should have a method for checking whether an entry exists or not.
i am just learning flask, i am not expert not professional
and i know mariadb and mysql
so i wanna go with them first before i go sqlalchemy
You're parsing the entries from your database
And with the entries of the database you for loop it checking if the username exists already or not
for a in query:
if str(email) == str(a.email):
if str(username) == str(a.username):
pass
else:
return (something)```
I recommend you learn flask-sqlalchemy, it will simplify a lot of things for you
django is alot easier kek
^^
alot of people says its monolithical
But like, you don't have to 100% use it's default settings, or it's built in admin / auth system, it's purely up to you.
yeah i saw it too
@toxic flame i mean i just began learning frontend and backend for 2month
i guess you programmed before so
nope
complete beginner 4 months ago
ohh
ohh
give me the site
yeah
the official documentations
but what i do is just dive right in and whatever problem I encounter I just google it
the python original website?@toxic flame
For python?
yeah
Yea
idrk lol
I wish school taught me languages
django has a very nice documentation btw
wanna dm me?
Sure
you should not use django-admin for this, use python manage.py runserver. django-admin is normally, used only twice: 1) to create a project and 2) to create an app in the project
well django admin will just run the same thing as manage.py in terms of running the dev server
Hello
First time using Flask as webserver (on a Raspberry Pi), it seems like I can't link/connect my javascript.
I did make a static and templates folder , and somehow my css-file does work.
Anyone can help me?
Thanks
yeah same
It's for JS loading, but I just tested it to make sure and it's still not working
hmm so ur directory is wrong then mb
yeah javascript 😄
ur using two ways to use the script
i just like to call it jaBascript because its dumb 😄
the url for (jinja 2)and the default in html
hmm they might interact strangely and f*** it up or something as ive said i dont use defer
uh that should be fine btw
well it stops my code from executing
ya mine runs fine with that error it might be something to do with pylint
ye
search on google theres a fix but i dont have time to search it up for u
what was wrong?
i had another one like this
db.integer
so how do i create the db now?
i run db.create_all()?
run
then import from ur file the class
then db.create_all() pretty sure
or from ur file import db then db.create_all()
i think
from server import db
db.create_all()
C:\Users\Apoel\AppData\Local\Programs\Python\Python38\lib\site-packages\flask_sqlalchemy_init_.py:833: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the
future. Set it to True or False to suppress this warning.
warnings.warn(FSADeprecationWarning(
this is the error
Add SQLALCHEMY_TRACK_MODIFICATIONS = False in your config file
Hey guys, i'm looking best solution to store meta data for index page ( title, description etc). What best practice to do that?
For example i have this data for view-detail, but for list-view not sure how to implement that correct
i need to tie in a web scraping application from an external source that can take in information given on a web page. how would this be accomplished? example: web page gets a user input number. application takes that number, inputs it to a search in another website, gets information on that site and returns it on the web page.
i have this application made using selenium and tkinter for a UI but work is not allowing this anymore so i want to just throw it in a web page some how.
how would i accomplish this?
How I did mine was using django, but mine is very simple idk if that would be any use.
it literally scrape covid data from the govt website and pass the info to HTML/CSS, I didnt use database cos I dont see the point.
How to learn advance things of Django
go through docs
and there is also stack overflow
Advanced training for the Django web framework.
form.whatever.data = whatever or if your are using sqlalchemy then form = WhatEver(obj=whatever)
Not using wtf forms?
request.form["whatever"]
its mostly because its disabled
since u already know a inital value u can do something like ```python
name = 'value'
form_name = request.form.get('name', name)
print(form_name)
django?
You don't learn advance things, when you encounter a problem, you find the documents for that part. Hardly people remember all features of Django
Hello guys who know very well django please
I guess u have to import it
when i open my database i can't see any data. Can someone help me
C:\Users\Apoel\AppData\Local\Programs\Python\Python38\lib\site-packages\flask_sqlalchemy__init__.py:833: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the
future. Set it to True or False to suppress this warning.
warnings.warn(FSADeprecationWarning(
flask wont let me create database
flask sql alchemy
Can’t do that either I have preset values in more elements on the form that also return none even with disabled off or not so disabled isn’t the issue...
I'm not sure how to differentiate between a guest and a user when the frontend (Vue) and backend (Python/Flask) are completely separate. I want to show a landing page with separate navbar to guests, and one with the tools to the authenticated users.
There's an API route that checks whether a user is authenticated using flask-login.
@bp.route("/isLoggedIn", methods=["GET"])
def check_if_logged_in():
return jsonify(user=current_user.is_authenticated), 200
And I thought of simply checking this, and if it returns true set a Session Cookie that essentially goes: isUser: true and building the navbar based on that. But, users can simply modify this and it doesn't feel correct.
As I'm using Vue, requesting the route each time wouldn't be a good solution, as I'd have to rerender the navbar. Some searching on Stack Overflow and Google didn't help.
So... what's the best session, one-time approach to telling the difference between users and guests?
Hi, is there a way in django to add a filefield to a model class ? I know that you do the opposite way , but the other i'm not sure, this is what I want to do:
user=models.OneToOneField(User, on_delete=models.CASCADE)
class Meta:
form=FileFieldForm```
class FileFieldForm(forms.Form):
file_field = forms.FileField(widget=forms.ClearableFileInput(attrs={'multiple': True}))
class Meta:
model=User```
I'm having issues with flask_socketio, and can't get it to run. I have installed the correct versions as per the flask_socketio wiki, however get errors out the ass when trying to connect. (traceback here: https://haste.warsawpakt.xyz/wegifuv.sql)
Here is the python code and the index.html file, respectively:
https://haste.warsawpakt.xyz/isitume.py
https://haste.warsawpakt.xyz/afutave.erb
Here is the output of pip freeze:
bidict==0.21.2
click==7.1.2
dnspython==1.16.0
eventlet==0.30.1
Flask==1.1.2
Flask-SocketIO==5.0.0
greenlet==1.0.0
itsdangerous==1.1.0
Jinja2==2.11.3
MarkupSafe==1.1.1
python-engineio==4.0.0
python-socketio==5.0.4
six==1.15.0
Werkzeug==1.0.1```
how does one parse html to get a description out of it?
at least, I think its html
async with ctx.http.get('https://www.explainxkcd.com/wiki/index.php/2419') as resp:
text = await resp.text()
print(text)
beautifulsoup
thanks bro
np
I got pretty far so far
Just trying to get the thing right below a thing
from h2
I think I can get it
@native tide I just found there's an api for the website
use that then
lol
hello
can anyone suggest me any tutorial on how to a make live counter-like django app(i.e. when you press upvote on reddit, it updates immediately, in both front and back end)
is it possible to automatically set enviromentals when running app.py?
instead of manually typing export key=value
You can use Token authentication. I remember vaguely using it with Flask, but can't remember. iirc werkzeug-security has the authentication(s) you are interested in.
Have your model, add a filefield.
Then you can have your form, it will be a forms.ModelForm and specify the model & fields within the Meta class, your form will now have the same fields as specified in your model.
Django serves as a backend API, and you want things to update without refreshing the page (AJAX). That's a job for a JS frontend framework like React/Vue/Angular etc.
could this help?
what do you think is advanced django? I think that it's just caching, signals, and APIs, is there anything else?
i solved it thanks bro
hello
in the picture I am making a webpage where I want the logo in navbar to be in middle. Now I did it using margin left which is not a very good thing cause when I resize windows it gets messy
is there any other way?
This seems like overkill when all I want is to see whether loggedIn = true...
@west wren well, I dont know how else you will differentiate one user from another :D
I need to make some web backend for a constrained environment, i.e. router. I'd rather use python because it's easier to write in and lets me reuse code from other projects, but the target environment is too small for full python + libraries. What are my best options?
The CSS for my admin page in Django isn’t working and shows only the base html, any advice?
have you deployed it somewhere ??
or you are running it on local machine ?
usually it's a case of loading static files (i think)
try 'python manage.py collectstatic' and then change your static directory (from settings) to that directory
yes I am using bootstrap here
I’m running it locally, only shows the html
have you added '{% load static %}' on top of the html file ?
Truth be told I didn’t touch any of the admin files, I was trying to push the next version of my website up but kept getting a 400 error, don’t know what I did to mess up the admin page
Ah ok I think I see, for some reason when I set debug to false it messes things up, setting it back to true has it all working correctly
weird cause debug serves a totally different purpose
ohh ok
Weirder still, turning it off and on again fixed everything
But thanks Don, I do appreciate the help
Hey Guyz, I am facing a problem in Google Developer Console that I am unable to create my billing account as my transaction keeps getting error even after the successful OTP submission..thus I am not able to get API credentials.Has anyone gone through the same problem before?
Yes
can I see more code
because it should work fine
also maybe removed disabled on this one input called name and see if you can get the value
also check the post data in chrome debugger tools
Hello, i have a question. I am coding food ordering website (django) and right now i have done orders for nonregistered users (via cookies), but now i need to create orders for registered user. How should i do that ? i need cart (stored in cookie for nonregister) to vanish when user logs in and load his saved cart (dunno where to save this cart) and when we logs out load the cookie as he is nonregisted one. Is there a way how to do this somehow ? Thanks
remove the cookies when he logs in ?
oh yea sure, but i dont know where or how to save logged user cart (i dont want to save every orderItem in database on "add to cart" button click)
Ive said this multiple times(Not trying to sound rude in any way), there is only one disabled element every other one is not disabled and they also return None.
are the other elements just basic input type text though ? whats the chrome post data saying ? also can you send your whole form element ?
i think maybe db is the best, because they could switch devices and you'll want them to have their cart. just update the cart in db when they add/remove
let me get the full form element and be code
@uneven wren just post to the db in the background so you don't have to refresh the page everytime they do it
Sure i will save it to database later, but i dont think its good to make request to db everytime logged user clicks on "add to cart" i was thinking to save it to session somehow
okay ima make a paste nvm thats way to large
!pypaste - nvm forgot what its called
!paste
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.
but how you gonna know when they exit the browser ?
I think you'll have to query the db when they click add to cart, I may be wrong but I don't know another way
that is true.. session will vanish when i will close browser right ?
depends if the cookie has an expiry
i was thinking about second cookie but that is not possible right ?
am using django, but it will have similar func prbbly
Also the API responds with
[SQL: UPDATE ban SET username=?, userid=?, images=?, reasons=?, banstart=?, banend=?, notes=?, appealable=?, bannedby=? WHERE ban.username IS NULL]
why are you using a third party to do the request ?
the request is done when the user clicks submit - nvm i see this is another request after you get the data, i think?
And the return from update/ban does
http://127.0.0.1:5000/edit/ban?name=None
As the URL instead of
http://127.0.0.1:5000/edit/ban?name=test
What happens is the form sends to /upload/ban and then the route for /upload/ban sends a request to a API
Idk WHY I DID THAT WAY
But I think its because of something I encountered with the actual adding and not editing
can you open console in chrome, go to network, submit the form and check the data is actually being submitted correctly
instead of using request module, you could create a function somewhere, call the function, and then send the data
I just prefer using request module
SOMEHOW IT WAS THE DISABLED???
I swear I tested it without it
already
I just
Thanks for your help anyways @past cipher
wait
nvm the API is still having issues
its still saying
[SQL: UPDATE ban SET username=?, userid=?, images=?, reasons=?, banstart=?, banend=?, notes=?, appealable=?, bannedby=? WHERE ban.username = ?]
give me a second
ok fixed it
I am
whatever thanks @past cipher
Who can recommend a good Django course?
@native tide Do you want to work on a project together? I got 4 down, looking to do one more maybe a bit bigger, take a look at my portfolio, www.christianlfonts.com
Hello, so on django it's really specific on the url addresses, for instance if you put login/ the address has to have a / on the end for it to work, is there a way to support both? without a / and with a /
@toxic flame the reason it's like this is because when you use a web deployment software such as Apache or Ngingx you will notice that the / at the end means that it's a directory. When you have something without a / it means that its looking for a file.
So, is there no way?
@toxic flame the reason it's like this is because when you use a web deployment software such as Apache or Ngingx you will notice that the / at the end means that it's a directory. When you have something without a / it means that its looking for a file.
@haughty turtle TIL
What's TIL
today I learned I think
Sure I wouldn't mind, maybe in a few weeks though. Atm I am already working on my own project (and these are massive, they take me a month or longer) and plus I recently got into freelancing and have a client, after I work on those I have 0 motivation to continue coding in the day
Hello ! still struggling on this issue, is there anyone that could help? Thanks! https://stackoverflow.com/questions/65975468/how-to-create-update-manytomanyfield-related-models
If I am hosting my django site on heroku do I need to change the data base from sqlite to postgress or something?
Hello who know django very good ?
sqlite is good for websites with smaller number of users
But, is it necessary to change to what heroku offers?
Do you know how to migrate to Postgre ?
if you know then you can keep it however you like, if you don't then you should learn cause, most web apps would use something other than sqlite
No...but can learn
Through separate API calls. This is purely for showing a navbar for guests (a landing page) and a navbar for users (with the appropriate links).
If they click on a link, they will have to then further provide authentication to have it be populated with their user-specific info
Ok, Thanks 🙂
Take Developer Ecosystem Survey by JetBrains
https://t.co/S8US6FsJAQ?amp=1
Hello
I want to learn Web Devloping
Can you all just tell me a few answers?
Q.1 Which sources should I use for learning Web Development
Q.2 Is Web Development good or Python?
Q.3 Any books to use to learn Web?
Q4 Any app on PlayStore that I can use?
Anyone who knows please tell me
PLEASE
How can I make the django admin panel only available for 1 ip address if another ip address tries to access it they'll get a 404 error
Thanks 🙂
hi i want to update the row when update button is pressed
when i click on update a pop up apper's here i need all the fields against row and update it in database.
i am using flask
Hello i used a script to scrape instagram comments from a post but it's only scraping 25 and the post has 600
Help please ?
@glad patrol set the modal as a form, when you click update on the list use jquery to update the form with hidden input type contain the id of it, after that just send the POST request to update with ajax
@gaunt marlin can you share any resource link or video
Sure, how are you going to know how to route some people's request to the guest API and other people's request to the user API?
@glad patrol here an example https://stackoverflow.com/questions/38961333/change-form-input-field-value-with-jquery-within-a-bootstrap-modal
your update button on the list should have attribute with the id of the object row id, on button click pass that id value to the modal
pls come to dm
sorry can't right now i'm in the call at work right now
but i hope that example help you
your example you get id ?
Hey guys! I want to build a real-time candle stick chart. My backend will be Python and Django, but I know Django is not good at styling. And I am a beginner for front-end language and web-development, so I get struggled for choosing the JS framework. I want to ask which framework is better for combining with Django. Vue, React or Angular?
$('.btn-rating').click(function (event) {
event.preventDefault();
$("#rating-form").attr('data-class-id', $(this).attr('data-id'));
})
there this is more simple @glad patrol
ok this will only get the id form each row
yes but it pass the value in the form/modal i have
!codes
i forgot the link to post the long code one...
@glad patrol welp i just gonna post it on pastebin https://pastebin.pl/view/001fb6f4
Pastebin.pl is a website where you can store code/text online for a set period of time and share to anybody on earth
it's the html for the form in modal
can someone please help me here?
https://stackoverflow.com/questions/66024845/django-reduce-number-of-database-queries-on-bulk-update
thanks a lot!!!!
any solutions will really help me
yes that is the point, when click on update button each row you pass the id of that row object to your modal
please anyone?
cleaned = [obj for obj in data if not hasattr(obj, 'is_default') or not obj.is_default]
self.model.objects.bulk_update(cleaned, ['position'])
for instance in cleaned:
# we trigger signals manually because django doesn't do
# the same for us during bulk_update
post_save.send(sender=self.model, instance=instance)
this is what I am doing.
For every instance in the for loop a trip is taken to the db for post_save.send
why? Can I reduce this?
@gaunt marlin thank you i will try
anyone for help? https://stackoverflow.com/questions/65975468/how-to-create-update-manytomanyfield-related-models
you loop through the manytomany_field.all()
https://stackoverflow.com/questions/1194737/how-to-update-manytomany-field-in-django
Thanks man! appreciate it
here the docs for it https://docs.djangoproject.com/en/3.1/topics/db/examples/many_to_many/
@glad patrol is django ?
@native tide flask
oh :c i can't help you sorry
!code
Here's how to format Python code on Discord:
```py
print('Hello world!')
```
These are backticks, not quotes. Check this out if you can't find the backtick key.
Hello
why do i get
like this ?
oooooh it has to be templates manwatafk lol
wierd
its not rendering the h1 text tho
idk im following a tutorial
try to end block with its name like: endblock body
what are you trying todo?
and of course make sure that your file is at same path as index.html
Can anyone see whats wrong with my code. I am trying to login a user, and allowing persisting session across multiple subdomains
init
app = Flask(__name__, subdomain_matching=True)
app.secret_key = 'dsfsdfdfgsfsdsdgfdsf'
app.config['SERVER_NAME'] = "local.test:5000"
app.config['REMEMBER_COOKIE_DOMAIN'] = '.local.test:5000'
app.config['REMEMBER_COOKIE_SECURE'] = None
Can I use django and a react native together?
Yes, django as the backend and react as the front end.
hey guys, I used Flask, now I'm ready to move on
what's the best way to learn django
Does anyone know what's the best way to inspect the value of variables while a flask app is running in development mode using PyCharm?
I mean a flask app that's actively running
i don't think you can inspect the element of a backend variable while its running, unless you stop it, add in print statements on the routes where the variable is, based off what you're sayng anyway
Shame
what is it you want to do exactly
it's a quite complex API and it would be impractical to have a verbose mode because it would have to print so much
I want to be able to inspect variables in an ad hoc fashion
similar to how if you have a console open in pycharm you have the menu which shows all the variables
like that but for a script that's actively running basically
Hey, guys I've been trying to host my Django app on an Apache server for almost a month and I can't figure out why my application doesn't get hosted corretly
Can I get some help ?
[Wed Feb 03 19:30:55.769191 2021] [wsgi:info] [pid 8622:tid 140359668412480] mod_wsgi (pid=8622): Shutdown requested 'gbot2.alf.net'.
[Wed Feb 03 19:30:55.769532 2021] [wsgi:info] [pid 8622:tid 140359668412480] mod_wsgi (pid=8622): Stopping process 'gbot2.alf.net'.
[Wed Feb 03 19:30:55.769553 2021] [wsgi:info] [pid 8622:tid 140359668412480] mod_wsgi (pid=8622): Destroying interpreters.
[Wed Feb 03 19:30:55.769565 2021] [wsgi:info] [pid 8622:tid 140359668412480] mod_wsgi (pid=8622): Cleanup interpreter ''.
[Wed Feb 03 19:30:55.780961 2021] [wsgi:info] [pid 8622:tid 140359668412480] mod_wsgi (pid=8622): Terminating Python.
[Wed Feb 03 19:30:55.805720 2021] [wsgi:info] [pid 8622:tid 140359668412480] mod_wsgi (pid=8622): Python has shutdown.
[Wed Feb 03 19:30:55.805809 2021] [wsgi:info] [pid 8622:tid 140359668412480] mod_wsgi (pid=8622): Exiting process 'gbot2.alf.net'.
[Wed Feb 03 19:30:58.064814 2021] [wsgi:info] [pid 9310:tid 140688627171392] mod_wsgi (pid=9310): Attach interpreter ''.
[Wed Feb 03 19:30:58.068810 2021] [wsgi:info] [pid 9310:tid 140688627171392] mod_wsgi (pid=9310): Adding '/home/adp_py/apps/gbot2/mysite' to path.
[Wed Feb 03 19:30:58.069126 2021] [wsgi:info] [pid 9310:tid 140688627171392] mod_wsgi (pid=9310): Adding '/home/adp_py/.virtualenvs/gbot2/lib/python3.5/site-packages' to path.
That's the apache_errors.log
So how do i get django on pycharm
ik im dumb
@fickle rivet are you using modwsgi?
Never heard of it
nevermind figured it out
you do not need pycharm to run django
ik
I prefer pycharm over vs
and others
Also pc shit and cpu cooler laoud af when using vs
hello how can i get the ip adress of an user with flask ? I tried request.remote_addr but it's give the wrong ip ... sorry for my english
cloudfare
X-FORWARDED-FOR is the right header to use
ok thx
Now it works but it gives a string with two Ip
It's normal ?
In the examples above, 203.0.113.1 is the original visitor IP address and 198.51.100.101 and 198.51.100.102 are proxy server IP addresses provided to Cloudflare via the X-Forwarded-For header.```
So the first IP address is the visitor and second is the proxy server.
What you using the IP address for?
Also remember, that with IPv6, you could end up with a situation where you only have the proxy server for X-FORWARD-FOR and then you will find the IPv6 in Cf-Connecting-IPv6
Ok
Thank you
Hi All! I have a Django question that I haven't found a solution for, how can I make css background image url dynamic with the Django template tags? I've tried this approach and it's not working <div class="user-image-div" style="background-image: url({% user.userprofile.image.url %};)">
Anyone know how I can find this elemnt in selenium? find_elements_by_class_name doesn't seem to work
with flask, is there a way to have a route with the same name for a different request method like it is with expressjs?
eg what i want is
app.get(() -> {});
app.post(() -> {});
instead of
@app.route("/route", methods=["GET", "POST"])
def route_func():
if method == "POST":
# do X
elif method == "GET":
#d Y
Does flask support Class based views.. then you could have methods for get and post.
I know Django has that ..
Yes, <VirtualHost *:80>
ServerName gbot2.alf.com
LogLevel info
ErrorLog /home/adp_py/apps/gbot2/apache_errors.log
CustomLog /home/adp_py/apps/gbot2/apache_custom.log combined
ServerName gbot2.alf.net
ServerAlias gbot2.alf.net
Alias /static /home/adp_py/apps/gbot2/mysite/staticfiles
<Directory /home/adp_py/apps/gbot2/mysite/staticfiles>
Require all granted
</Directory>
<Directory /home/adp_py/apps/gbot2/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess gbot2.alf.net python-path=/home/adp_py/apps/gbot2/mysite:/home/adp_py/.virtualenvs/gbot2/lib/python3.5/site-packages
WSGIScriptAlias / /home/adp_py/apps/gbot2/mysite/mysite/wsgi.py application-group=%{GLOBAL}
WSGIProcessGroup gbot2.alf.net
</VirtualHost>
I've followed many guides and I came up with this conf file, I belive I've done everything corretly, but the error message is so obscure I can't figure out how ot tackle the problem
h
Yes
can someone help me name something? i have a list of 50 categories, and each user in my application can choose to subscribe to one or more categories. i need a name for "the list of all categories, with a true/false flag on each category, identifying whether the user has subscribed to that category".
so this would be a resource like /users/{user_id}/categories-with-selections , i just need a good name for categories-with-selections
trying to balance verbosity with clarity
Subscriptions?
You could also call it Notifications, if you put a bit of text just saying that the notification will be a push or marketing message for the category 🙂
these aren't notifications specifically
it's more like a "selection"
something to show on the user's home page
Subscriptions seems fitting @surreal thicket
heh, maybe i didnt explain clearly
i will have one resource that returns a list of category IDs
and another that returns this list of all categories, annotated with whether the user has selected it
so i have
/users/{user_id}/preferences/tags
User's list of selected tag IDs
/users/{user_id}/preferences/???
All tags, with {..., "selected": true} if the user selected it
you all still think "subscriptions" is the way to go?
no
you should have this
/users/{user-id}/preferences/tags/ids
/users/{user-id}/preferences/tags/selected
So no need for adding the extra {"selected": true"}
@surreal thicket
ah
well... this is a specific request from the frontend 😦
they want it all in 1 request, i know it kinda breaks the REST model but it's a performance consideration
well i would still go with that, just add the {"selected": true} part
well it makes the most sense tbh
would you have /users/{user-id}/preferences/tags return anything as well?
hmm, it depends, it could return all tags, selected and unselected
even though it's on the user resource?
we will definitely already have top-level /tags for that
well then /users/{user-id}/preferences/tags should not return anything
this is actually one issue i've had with the rest model as i start to learn it on a professional level, seems like you could have multiple endpoints all doing the same thing
what framework are u using?
as a hobbyist who cares? but designing apis for longevity is hard stuff
my team is using tornado
nothing specifically rest-oriented, the rest part is somewhat of an organically growing layer on top of the tornado stuff
I am guessing this is a big project, correct?
yes
and i come from the data science world so professional web dev is somewhat unfamiliar territory to me
I am working on a huuuuuugeee project with some other devs, mainly frontend ones, the frontend is based in react
and I am using a microservice structure for the backend along with another dev
If you are multiple backend devs then building something under a monolith can result to things like this seems like you could have multiple endpoints all doing the same thing
Also really hard to scale properly as it scales linearly
Just my input ofc
this is actually for one of our microservices 😛 or is rest for microservices is considered an anti-pattern?
No its correct
Alright, then you probably have multiple endpoints in different services that give the same or similar responses
right?
right now, no. we don't have a standalone tags service yet, and users only come from 1 place
so all of these endpoints i described, for now, would be under my purview in this one service
Hmm, that is not correct
You should have everything user related under one microservice
tags are applied to content, and users can select their list of tags for filtering content by default on their homepage
so tags aren't just for users
Because if what you are building contains routes for other things, and they are used all the time then the route u mentioned earlier will get delays for no reason
Oh i see what you mean
Still, you should have different endpoints for these
If this is for a social network then this is our approach on a similar thing:
Everything user related stays within the user related microservices
Everything home page or content display stays within their respective microservices, even if that means that some endpoints are pretty much the same
They serve a different purpose thus they are listed accordingly
right, that much i understand
what about something like this? /tags?user={user_id}
heh, that's a separate issue...
You would clot the /tags endpoint, but you can do it for sure. No param means all tags are retrieved, else they are user specific
that was what i was thinking, yes
what do you mean by "clot"?
as for how our backend is set up:
- tags are stored in our CMS, which has its own API
- users are stored in a database hosted by a cloud provider
- the microservices are running in hosted kubernetes with istio
Basically both user specific and general calls would be made to the same endpoint
I am hoping this
:
You are not loading the tags each time from the db
Cause, if you are then that will be heavy asf once that route starts getting attention
😅 yes, we can cache the list of tags
I wouldn't cache them
well i would
but in redis
and load them with a background task from the cms api
That way you can access them globally
the list of tags will change very rarely and the cache can be invalidated manually. but unfortunately i don't have the ability to run a message broker, unless i run it inside the container which seems to be somewhat pointless
since u are using k8s, it still hasn't dropped docker in its public version i think, you can run redis as a service
oh, is it going to drop docker at some point in the future?
Yes, they have announced it
it's all cloud hosted/managed anyway so i assume we will still have docker access
Not sure, but you should think of your microservices architecture more
The need for a message broker is big
trust me, i want to. i just joined this team and they've been working on this all somewhat independently from each other
dev A works on service 1 and dev B works on service 2, and they sometimes meet to discuss things
well that's how it should be, but isn't there a general plan of how things talk to each other
right. ive been trying to get more broad architectural discussions going and avoid snowballing cruft & tech debt, but features must be delivered in the meantime
Before we started our project we spent weeks discussing it
i will float the message broker idea, the team is pretty open to new ideas but short on time to "experiment"
I mean, it is really easy to use
And it will help you solve a lot of problems
mainly cause its blazing fast and can you can load pretty much everything on it
then just have background services updating the db through redis
noted, i have worked with applications that use redis but never used it myself
a year ago i was doing machine learning, and now here i am in the web dev trenches
Haha nice, I have only done web dev
mainly backend
I got some really good frontend devs in my team
so i handle most of the backend myself
its nice to be doing something that i dont know much about and am constantly learning, and i appreciate the advice
well web dev is easy to learn hard to master
also its funny, so many people try to go from dev to ml, i did the opposite, although mostly out of a sequence of coincidences and weird life choices
so i see, there is quite a lot to keep track of in order to do things right
Haha, in a production environment it is entirely different than dev
But yea ML is on my to-learn list
i have it in the 4th semester of my uni as well
I learnt web dev completely by myself
i've actively avoided going into #data-science-and-ml or any of my usual stats/datasci/ml chatrooms because i was getting burned out. but one day im sure ill be able to help advise you on it 🙂
I asked some questions here in my early steps but i haven't gotten much help since then, i mostly reply to questions and not ask hah
awesome, i will make sure to ask them then haha
Also, I got one more question for you
Since you are building a microservice why are you using tornado?
Is this what you know best or are you forced?
forced 🙂
the microservice architecture was already set up when i arrived
and tornado was already chosen for the web framework within each backend python service
i should also note that we are trying to transition to graphql, which at least solves the data modeling problem, if not the query performance/bottleneck problem
we already have a graphql service running on top of everything but not everything is exposed through it, so we have lots of frontend stuff hitting the rest APIs and not graphql... its a bit of a mess
GraphQL is insanely good if u get it right
I am still trying to learn it but we will transition to it soon
{
user(id:1234) {
tags {
id
display_text
selected
}
}
}
this would be the ideal world for me
well... actually no
same problem
inversion of whether "tags" or "user" is the top-level thing
{
tags(user_id:1234) {
id
display_text
selected
}
}
hm
That sounds the best to me
👍
would it be better to do tags/{user_id} or tags?user_id={user_id}?
since for now i have to just do it in rest and worry about graphql later
Go with tags?user_id={user_id}
will do
i just realized that we need to have /tags/{tag_id} anyway 🙂
this has been extremely helpful, thank you
Hello , I am thinking of learning Django framework, what all should I know before starting to learn Django?
i think you should have at least a basic understanding of:
- OOP and python classes
- how a relational database works (like postgres/mysql/sqlite)
- how a URL is constructed
- HTML
I need help in heroku hosting
Thanks, I am familiar with all the above mentioned except the URL construction, I should check into that, thanks
i just mean understanding the basic parts of a URL: scheme, domain, path, query
Okays 👍
Hello what is the best way for display pdf page on a html page ?
container?
Hello guye i am new to web development. I have some experience in HTML and CSS
which lib should i use for python web dev? Flask?
Depends - how hectic is your project.
Django is great for when you need an admin and storing data
Flask is great for, I feel and some may disagree, more pure play API endpoints 🙂
Hello
How can i set cooldown on submitting form in django?
@wraith cypress learn for fun or learn to integrate into your current software?
Cloudflare have a good chat example of Websockets https://blog.cloudflare.com/introducing-workers-durable-objects/
to integrate to django specifically
but I could use anything helpful on the topic in general
If you are willing to pay a bit, I recommend https://pusher.com/
Super easy, I did it in like 3 days for a real time barcode printer
because you can make normal REST API requests to Pusher - which sends the WS messages
will check it out, thanks!
The problem with websockets at scale, is actually loadbalancing cause you can;'t move sessions between normal LBs - so over time, some LB's might get super hot and others super cold
Hence get Pusher to do that hard work of managing the actual Websockets
so you think it's worth it since you pay for getting rid of the headaches of websockets and have to think less about them
also how's the latency with it?
Well, I was EU - EU - so about 1.5x slower than what I would expect a REST call
but the nice thing - you deliver to Pusher, you can kind of stop having to send that data.
So if it's a big message, and the client has a slow connection - not your issue
nice, thanks for letting me know about it
Also, they got SDK for iOS, Android and React 🙂 Sweet
How in gods name do import Django to PyCharm without these
Hey @native tide!
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: