#web-development
2 messages ยท Page 10 of 1
yeah
this is actually driving me insane
it's gonna be the smallest detail
i've been looking for like an hour now
for me that works on chrome with the !important
just a local file
are yo usure that the path is currect
the homepagestyle is in root of static?
open the chrome dev console, see if its loading the file
well the css is in \Desktop\Code\Languages\Website\static and the php script is in \Desktop\Code\Languages\Website\templates
does it have to be an html file?
uh huh
try
<div class="container" id="wrapper" style="background-color: #ff6600">
<p id="loginforminfo"> Login to continue to the site: </p>
</div>
yeah that works
for some reason it can't load the file
it's weird, if i use a local href then it displays the "login to continue etc" text just without styling, while if i use the coded href then it doesn't even display the text
it's not finding the file
the css
if i run the server from the flask script, then what is the root directory of the webpage?? where the flask is ran from?
not sure
finally got it to work!! thanks so much for your help ๐
๐
does django/flask have angular support?
angular has nothing to do with the server
but like
it's client-side javascript
right
if the user presses a button
how can I pass that action from angular to flask
if that makes sense?
that's really going to be up to you
I don't recommend angular for that though
that's massively overkill
wdym
you should be able to do it with nothing but javascript itself
actually come to think of it
basically everything I need can be done through js
most of it is on a rest api anyways
ts file is type script right?
yep
lol
I have a questiron
I am following a tutorial on how to like do angular
and the tutorial has a sidebar which allows navigation between pages
but I dont know how to make the user authenticate first
If I use javascript to scroll up and down on a website with selenium, will the website I am scrolling on know that I used javascript to perform those actions?
How do I enable a normal smooth scroll without using javascript?
why are you concerned about a website knowing you used javescript to scroll?
and just so you might know 1. why are you trying to bot a website using js
and 2. no they would not know.
ERROR in src/app/login/login.component.ts(2,10): error TS2305: Module '"C:/users/Drew/Desktop/MCP/node_modules/angularfire2/index"' has no exported member 'AngularFire'.
src/app/login/login.component.ts(2,23): error TS2305: Module '"C:/users/Drew/Desktop/MCP/node_modules/angularfire2/index"' has no exported member 'AuthProviders'.
src/app/login/login.component.ts(2,38): error TS2305: Module '"C:/users/Drew/Desktop/MCP/node_modules/angularfire2/index"' has no exported member 'AuthMethods'.
src/app/login/login.component.ts(4,24): error TS2307: Cannot find module '../router.animations'.
rip
lol
bot.tags.get('ask')
Asking good questions will yield a much higher chance of a quick response:
โข Don't ask to ask your question, just go ahead and tell us your problem.
โข Try to solve the problem on your own first, we're not going to write code for you.
โข Show us the code you've tried and any errors or unexpected results it's giving
โข Keep your patience while we're helping you.
You can find a much more detailed explanation on our website.
Well i have a problem with hosting my server on a domain, its a VPS with a Namecheap domain.
And i dont know how to get it to run on that domain
So when you visit the domain does it currently bring you to the server but displays the IP and not the name?
its fine now mate fixed it with some Advanced DNS adjustments
I keep getting this error with this js ```python
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#Main_info").remove();
});
});
</script>
ValueError: unexpected '{' in field name
I later format some things
a reference on a solution I tried to use is: https://stackoverflow.com/questions/38662296/unexpected-in-field-name-when-doing-string-formatting, this could easily be not related to my end goal, if so, I apologize.
but doing something like doubling up the brackets in the script section above leaves another error
jinja2.exceptions.TemplateSyntaxError: unexpected char '$' at 163
163 is the second $ in that script
I'm not sure how I would fix the first Value Error and it appears that threads solution was improper for my situation, I thank those who have a better solution or know how I could fix such a thing
and only making the second set of brackets doubled up returns a similar error: jinja2.exceptions.TemplateSyntaxError: unexpected char '$' at 201
char 201 is the third and final $
I see no reason that js should toss an error, there are no template strings to escape. check your stack trace again or comment out the js to see what's throwing the error.
it has to be those curly brackedtgs
brackets
seen as formatting brackets
if you mean the $ char issue, I have no idea
I suppose a solution could consist of me making a separate file for the script, but I'm not sure how to do that and I'm also not sure if that will even help
hey
how come using vue.js
<!-- production version, optimized for size and speed -->
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<body>
<div id="app">
{{ message }}
</div>
var app = new Vue({
el: '#app',
data: {
message: 'Hello Vue!'
}
})
</body>
that code
doesnt actually render hello vue
does brackets realtime not render scripts?
isn't it because when you use double curly brackets, it prevent them from being formattable
and that makes message just message
I'm not very good at this, but it could be
you either need to define new delimiters, square brackets is a good choice, for vue or escape with {% raw %} {{ whatever }} {% endraw %}
wtf
<div class="login">
<h3>Sign In</h3>
<input type="text" v-model="email" placeholder="Email"><br>
<input type="password" v-model="password" placeholder="Password"><br>
<button v-on:click="signIn">Connection</button>
<p>You don't have an account ? You can <router-link to="/sign-up">create one</router-link></p>
</div>
right
<style scoped> /* "scoped" attribute limit the CSS to this component only */
.login {
margin-top: 40px;
background-image: "../assets/airplane.png"
}
why doesnt that
make a background image
can I not use css like that in a vue.js template?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>vue-firebase-tutorial</title>
</head>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
<style>
.app {
background-image: '/mcp/src/assets/airplane.png'
}
</style>
I even tried adding it to the app injector?
probably can't resolve the path.
@warm pumice do you have post set up in your view as well?
what do you mean by view?
sry
not familiar with some terms
@gentle sapphire
@app.route("/users", methods=['GET','POST'])
i've got it set up here, if that's what you mean
yes, it is
the strange thing is, the submit button works on my login and register pages but not on this one.
not entirely sure why, i've tried comparing the code for both of them and it should work lmfao
<form method=post>
<input class="form-control mr-sm-2" type="text" placeholder="Profile" name="search" value="{{ request.form.search }}" autofocus>
<input type=submit class="btn btn-outline-dark my-2 my-sm-0" value=Search>
</form>
anyone know why this post request isn't going through?
there is a code, I don't remember what it is that you probably find in those other pages
and in {{ }} that is above the request codes
i'll check once more
nvm i got it LMFAO i had two <form> tags and that was causing the issue
no idea how i didn't see that
thx for ur time
glad it worked
hey
can someone help me?
I am using vue.js
I have a sidebar
but I only want to render it after the user logs in
so I cant put it under the index.html
Anyone here able to help with deploying a celery/flask/rediscloud app to heroku? running into an error idk how to solve.
How exactly do websites connect two players within a game or some other creation
need some scrapy guides
is jquery still relevant in 2018?
@sour heath simple, usually using a rest api backend
or using a framework like django for a server side interface
but
if I wree you
I would start with the basics
people are saying to use sockets
ex. instead of a game, start with maybe just something simpler
well depends
yes using sockets would make the most sense.
if its more simple though, then you can probably get away with a rest api
its a one on one card game
Hey guys, getting a weird problem when I integrated my celery/flask/rediscloud app to heroku
When I follow my app url, after 30 seconds the request times out and I get an application error on the webpage, however in the background, the celery part of things still completes its process, however the result never gets to the webpage
Any ideas why this might be?
I thought using celery to run the process in the background was going to fix this problem
A little more info, I am using a genetic algorithm to produce a long list based on user input. the GA takes around 3-5 minutes to complete, so I am using celery to run it in the background so I don't get a critical worker timeout error, however even after implementing it all, I still get the error. But my heroku logs show that the worker still completes the GA and successfully gets the result. The result just never makes it to the webpage because as soon as the worker timed out at the beginning, an errorpage is shown.
Here is the heroku log: https://hastebin.com/ifakexilep.vbs
Anyone know about flask and being able to create like a browsable directory of my aws buckets, but caught but this might explain better https://stackoverflow.com/q/51259168/10057611
Hi Everyone
I'm super green regarding Selenium web automation and wanted to ask a question
Is it possible to continue from a certain line? As I don't want to keep spamming the lets say login screen or starting website but just want to continue from a certain point
I read about an addon for Sublime Text 3 and I am able to select a couple of lines to continue from
But how do I do that within the Selenium module?
@cobalt vale You would have to build that logic into your application
There's no real time warping
So you'd need to somehow save all the needed data that you got from the login screen so that you could load it later on
Checking how I can paste code in here
Can you maybe show me an example or refer me to an example online?
I'm not really able to find it @brave mantle
You won't really find an example for that
It's the kind of thing that entirely depends on your application
Yeah, true..
You'll need to be sure you're experienced in python before tackling more than a simple script
True, ah well, I'll just start at the beginning of the code again, it is not that big
thanks anyway
@brave mantle Can you maybe point me to a deathbycaptcha guide for Selenium?
You're looking to solve captchas with selenium?
The only real way to do that is, well, manually
via the deathbycaptcha api
ah, well I've never even heard of that
it's worth noting that most sites and captcha providers don't allow users to solve captchas automatically, or even scrape their sites
that's kind of the point of a captcha
Sure but then I'm not able to do any automations online
I'll ask elsewhere, thanks anyway
im failing to check the checkbox
tried every div but im getting always element not visible when using .click()
anyone got an idea?
anyone has any idea if there's a limit to scrapy crawl speed. I can only scrape 500pages/s on my computer
@queen fiber if it's a python question would you please post it in a help channel? I was about to write a wall of text non-python related and I don't wanna drown your question...
oh sorry i though this was the right category
It's more asking you for a favour haha
Mine isn't a python question so I can't use the help channel
Welp, here goes
Hello, I'm trying to implement an auth/authn flow using oauth2/openid and I am very confused about who plays which part; I'll try to formulate a question that makes sense...
Assume I have a web application WA, an authorisation server AS, and one or more identity providers IDP. I am to develop the AS part.
The goal is for the WA to know who the user is, and whether that user has permission to use the WA. I must:
- Ask the user for his email, and find out which IDP he belongs to [black box]
- Send the user to the IDP's login page and make him sign in
- The AS needs to check if the user is authorised to use the WA
- If he is, the WA needs to have his identity and an authorisation to use it; if he isn't, the WA needs neither.
What is unclear to me is where oauth2 is used/where openid is used, and if the WA gets an openid ID token (that will verify against the IDP) how does it know where to ask for authorization?
sooooooo, not sure if bs4 is considered web Development but its to do with the web. Basically I've got this error message but the error message itself has an error so im not sure how to fix it. Any ideas?
ive scoured the bs4 init file to no avail, i cant find "BeautifulSoup(YOUR_MARKUP)" anywhere. I might be doing something really stupid as this my first time using bs4 and/or a module this intricate?
@hard lagoon what's the first line of your file that uses bs4
(i.e. when you're actually initializing the bs4 object)
hey
Hey guys so Im a web dev coming from the LAMP stack and Im looking to swap out PHP for Python ๐ Any tips on which frameworks to use etc. ? I believe flask and django are pretty popular choices.
Yep, those are the two I'd recommend
maybe include some practical reasons as to why
yeah true, having a deeper read into it, Im going to start out with Flask just because it is light weight. Thanks for the input guys ๐
so Im going to try use Flask, Jinja2, and some SCSS of course ๐ here's hoping I can survive the docs ! ๐
@meager anchor
completely not related to python
but any idea how to create a canvas which takes the entire screen in p5.js?
hey guy, can someone help with something
so, i'm trying to create an api, so i'm new to this kinda of stuff and it's my first time doing in python
i'm with a little trouble doing it
i'm making like this
from flask_restful import Resource, Api
api = Api(app)
from app.api import tables
api.add_resource(CreateTable, '/CreateTable')
the problem i'm getting is that api has no attribute add_resource
what's that mean?
(i'm using flask btw)
it looks like u need the flask stuff @native tide
from flask import Flask
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class HelloWorld(Resource):
def get(self):
return {'hello': 'world'}
api.add_resource(HelloWorld, '/')```
What am I doing wrong with crsf tokens here, in the example below the if case throws a missing CRSF token error
{% if disp is defined %}
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
<h2 class="subs-title text-center">Thank you for subscribing!</h2>
{% else %}
<h2 class="subs-title text-center">Subscribe now!</h2>
<div class="subcription-info text-center">
<form class="subscribe_form" action="/" method="post">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
<input required="" value="" placeholder="Enter your email..." class="email" id="email" name="email" type="email">
<input class="subscribe" name="email" value="Subscribe!" type="submit">
</form>
<p class="sub-p">We Promise to never span you.</p>
</div>
{% endif %}
after a button click and the post disp gets defined is defined
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
return render_template('index.html', disp='yes')
else:
return render_template('index.html')
nvm found the problem!
whats better?
and @brave mantle sorry to bother you but i am touching up on python.
and wheres a good place to do so?
Neither is "better"
they're just different lol
I guess you could try some of the #295490247255523338
when i say touching up
i mean rebuilding what i know
could you do a quiz for me? @brave mantle
Not sure what you mean
How to shuffle a string (such as "asiuc90m2u34c092u") pseudorandomly in javascript?
With a given string
Nevermind.
hey there,
im trying to make a website with login in flask. but when i call login_user(x) with x being of my own user class i get this stacktrace:
[...]
File "[...]\frontend\app.py", line 54, in login
login_user(x)
File "[...]Programs\Python\Python37\lib\site-packages\flask_login\utils.py", line 161, in login_user
user_id = getattr(user, current_app.login_manager.id_attribute)()
TypeError: 'str' object is not callable```
what could i be doing wrong?
im guessing its because of my `get_id()` function in my user class, which returns a string with the id (`1000` in my test case), although im not sure what i could do diferently
getattr(user, current_app.login_manager.id_attribute) returns a string but youre calling it as if its a function
any particular reason youre doing that? lol
i personally am never calling getattr(...)
its called in \Python37\lib\site-packages\flask_login\utils.py
you can see that in the stacktrace
what is your user object and your login manager object?
and are you able to see what current_app.login_manager.id_attribute is?
@quartz maple Django includes a lot of things for you, it works better if your project is a more traditional website with a database backend, forms, admin pages etc.
Flask gives you nothing but a web server and a templating engine, and is more suited for bottom-up development and light weight websites or APIs; whatever extra you need you can bolt on, it's very well built for that purpose
In very simplified terms, to make Django "like Flask" you have to disable a lot of features that Django just assumes about your technology stack
To make Flask "like Django" you would need to add several extension modules like login, database, forms, etc.
for some reason ,the background color dosent seem to apply to my webpage
help plz
do the comments have a class for themselves?
you may want to give them a class for easier styling
those comments r printing from the database
im not worried abt that
my background color is not coming for some reason
no matter which ever color i try
idk that footer(?) seems to get a background color ๐ค
yea, so why shouldn't the comments have their own css (class)
the whole webpage
the eniter white background u see
i want it filled with another color
but its not geting filled
* instead of body?
nah, i mean the rest is already affected, but still worth a shot i guess
the other webpages work with background-color,wondering whats wrong with this one
iirc flask is more like express
pretty much
although you can also do the frontend with flask
but it's not required
@marsh canyon nothing's wrong with background-color, just both background and background-color work
django its full stack and Flask is backend ?
django is full stack out of the box yes
@native tide yea but its not working for some reason on that page,just a min code will be updated on github so u can see it there
with flask you'd need to add stuff like a database and frontend template engine
@marsh canyon ok
@native tide
the background color is not being executed in comments.html and also view-comments.html

and it works just fine with the others webpages except the comments.html and view-comments.html
i mean i have not used bootstrap yet,will use it soon once i figure out how i will be displaying stuff
dude those webpages r new,so i still dint get into complete css ๐
just testing those new comments and view-comments pages out ,lol
i still need to make base.html tho
hey, ive got another problem:
i was just working on something else, restart my flask app, and now this happens:
File "[...]/frontend/app.py", line 4, in <module>
from user import User
File "[...]\frontend\user.py", line 4, in <module>
class User(UserMixin, id):
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases```
so my obvious question is: what happened? it worked, and suddenly when i restart it doesnt? makes no sense to me. all i did was change a method that isnt even used yet
what's in you guys opinion the most optimal way to make your usual user management / data CRUDS app for a customer ?
@summer dirge could the User class be trying to use id as a mixin class?
bot.docs['id']
id(object)```Return the โidentityโ of an object. This is an integer which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same [`id()`](#id "id") value.
**CPython implementation detail:** This is the address of the object in memory.
i want to punch my face so bad rn but that would hrt
that was it
apparently i tried somethin
and never reverted it
Ye, it's trying to subclass the builtin id() function... Which is also an object ๐
I don't blame you, metaclass-related exceptions are always hard to decipher
has anyone used the dyanmic django scraper app? any feedback?
@marsh canyon weird question, but have you tried putting the color in quotes?
has anyone tried this out? https://github.com/Tonejs/Tone.js
currently thinking about doing something with it
I'm wondering how it would work with websockets performance wise
Sorry I was asking what framework(s) do you guys use for building admin cruds easily lol
Both Django and flask have good admin cruds
@queen needle that looks to me that Django is better
I think Django is better for more experience web dev
I must disagree. Flask gives you less for more, in my opinion. Since you have to build from the ground up, nothing is packaged for you and you select only the components you need, which ultimately affects performance positively. Also I've found it more easily extensible than Django
However I have some bias because I prefer lightweight frameworks in general
And as aways, "right tool for the job". It's overkill to use Django if all you're implementing is a REST api.
which is easest to learn @queen needle
Both aren't too bad, but Flask might be easier @quartz maple
Django comes with a number of specific batteries included. this is useful if you are familiar with those batteries and think they're a good fit for your project.
but for a beginner, this will almost never be the case.
so flask is a better choice.
however if you are following along with a good django tutorial (like Corey Schafers) it might be a good sink or swim style intro to lots of web tech
you'll learn about ORMs, migrations, class based views..
but if you just wanna make a simple website, flask is a great choice.
@deep cave i want to make a eCommerce Website
thats fully custom
and
it sells digital keys
Sounds like a Django project to me
(of course this doesn't mean Flask is a bad fit for it)
either framework could handle a project like that - but you really should learn to crawl before you start running the marathon that is making an eCommerce website.
If it's a toy project it can work, there are probably tutorials out there that eventually lead you towards building it step by step while learning
But when money is involved, security is the #1 priority so it would really be a bad idea to go live with it
Go live = allow people to use it regardless of where it is
Lemon and I are saying it is a tough and risky choice for a first project
So it's a toy project
Go wild then ๐
I'm sure there are tutorials out there. I'd recommend Django in your case
Well yeah, nobody can touch your website if you're running it locally without exposing it to the world. Including any customers of course.
It's just you and your website
Do you know what a port is?
So unless you forward port 443 from your router to your pc, nobody will have access to your site, even if they have your IP
or not have it on the default in the first place.
I still don't understand what you mean by "people can't touch it"
As long as you don't NAT from your public IP to your machine, it'll be completely obscured from the outside
As soon as you expose a single port to the outside, regardless of whether your application is hosted on your local machine or amazon or whatever, you're immediately subjected to the bad guysโข
Which is why I advocated against publishing an e-commerce website as your first project, unless you have someone experienced to help you out with debugging and security
especially if you're also managing user identity and PII (hi GDPR)
hmm, i want to implement a "chatbot" on my website that asks questions from the user and parses the answers and enters them to the database, any ideas on what /how i should do that
Anyone good with flask-sqlalchemy? Currently got my models and stuff setup but I want to display the schema of the database
Kinda like pgadmin except I just want to browse it
flask? django?
https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world this might be useful
also, remember to NEVER include private/sensitive data in a GET request
yes
@app.route('/')
@app.route('/index')
def index():
user = {'username': 'Miguel'}
return '''
<html>
<head>
<title>Home Page - Microblog</title>
</head>
<body>
<h1>Hello, ''' + user['username'] + '''!</h1>
</body>
</html>'''
that part has info on templating
Hey
What would be the best way to collect stats using Sanic?
Its p much async flask
I want to collect stats like
except it's insecure
you can use middleware i think
i really wouldn't recommend using sanic though
just use flask with gevent if you want async flask
ye I'm considering switching to Flask
but not quite yet
What would be the best way to do it in Flask then?
correction
I will be switching to Flask
just been a lil lazy
will look into it
Well, my issue is storing it
How do I efficiently store stats like that
@meager anchor
where do you guys format time+timezones, on the frontend or backend?
it seems I'm supposed to do this on the frontend
Moment.js is quite nice
there's a flask extension for it too
doing it in the frontend with something like js means they can update in front of your eyes.
1 minute ago can turn into 3 minutes ago if you just stay on the page
it's quite nice
it also handles localizing the time data to whatever is the correct output for that user - like showing MM/DD to americans and DD/MM to europeans or whatever.
it can even display stuff like the name of the day in dozens of languages
timezone format is best on frontend because it can then adapt to local time settings
yep
on the backend store a timestamp or something and then convert it to a formatted time in client
I second the recommendation of moment.js, great library
Moment Timezone allows you to do anything timezoney, too
I decided to go with this atm: https://github.com/date-fns/date-fns
don't need anything crazy at the moment
ideas how to make the login/registration page less plain are welcome! :)
don't mind the navbar just yet. it isn't finished
some css animations would go a long way, @native tide. maybe the field borders can fade in slightly when clicked. maybe placeholders and fontawesome icons?
also not crazy about the font on that h2
that looks quite nice to me, except there's some excess space at the bottom on mobile. not really an issue to me though, good job
@deep cave, that seems like a good idea
@1dude, I like the minimal approach too, but I'm hoping this project will be enough to get my next job, so want to make sure it looks somewhat 'professional'
as for the excess space at the bottom, I'm not yet sure what's up with that
it's because of the margin, but the margin-top and margin-bottom have the same % value
Hello everyone
i need help with a task that I have been given to create some kind of Rule Business Engine with UI or bot
which is as follows :
Objective: Build a small Rule Engine based UI (or bot)
Languages: Using node.js or Python or both
Business Use Case: Business needs to use the rule engine to communicate certain messages with users interacting with them. Business will configure certain rules from time to time and based on the combination of such rules, appropriate communication to the user should be tailored. Now, the rules are not all evaluated at one time but could even happen after a time-span.
Example Business Rules:
1. Check if the user is a repeat visitor or not (To check website visit of user using cookies in the last 7 days)
2. User input is "Good Morning" and local time is < 12noon, then say "Great day it is"
b) User input is "Good Morning" and local time is <> 12noon, then say "Its not a morning. isn't it ?"
c) User input is <> "Good Morning" and local time is < 12noon, then say "Hello, GM ?"
d) User input is <> "Good Morning" and local time is <> 12noon, then say "Hello, how are you ?"
3. If user input is blank, hold session and wait
b) If user input is anything else, close session and say "Thank you"
Please note that user input can happen even after few hours or days. Data will to be coming at a time. You need to hold the rules and evaluate.
Technical Requirements:
Build a run engine based UI
Provide a configuration for business users to change/edit/add rules with a GUI
Develop and Maintain a Webservice
Based on the rules, whenever the request comes, it should give response and respond needs to be based on previous request
Business users should be able to configure the rules dynamically without restarting the complete service
Note that there will be separate request response cycles and not all responses will be together together
Basic reporting of the user interactions
I can create web apps with Node.js/Express.js and Python django with using simple Bootstrap
but in this case I'm not sure that should I output this on a webpage with all the routes/model/controllers defined or bot building is done differently
hello, i use flask with jinja2. i give a dict to jina2
dict = {'_SimpleSeoTool': '#Google will take speed into consideration for mobile searches (Update: Rollout begins today) #seo #seotool #seomarketing #googleseo #serp #wordpress #blogger #blogging #webmaster https://t.co/W3bZk0WHkg'}
the website now displays ' for every '
How do i stop jinja2 from decoding that ' into ' ?
How exactly can I have a python file load into the html so it can be accessed by javascripts
using like ajax or something
Do django questions go here?
Yep, if they are about the web framework @unreal dagger
Also, how to get the text after ? in a url as string in js?
Hey doods, quick question. Im a little confused on how to setup HTTPS with Django. Do I need an SSL certificate or do I just change the security header and thats it? -- for my senior capstone project
My project is complete except I want to ensure we show "HTTPS" for a live map feed we have for a single device. I would appreciate not showing everyone on the web the exact lat/long of my house going across the internet ๐(edited)
Also: How would I use Django to setup this: In my Security class last semester we were able to setup a "login" so to say on Apache 2 so that you couldn't view the webpage without logging in. Should I just make it so that I myself has to log in on Django using the application layer? I want to block it at the protocol level not the application layer(edited)
Sorry, been a while so I may not be in-tune with terminology, which is why I really cant google it specifically
(re-posted from General to be more topic specific to the lurkers here)
You generally need a SSL certificate
But I have found using cloudflare as a host for your domain just as effective
They deal with the SSL certificate for you, give you stats etc
you need a cert
let's encrypt is a service which offers certificates for free (which are actual certificates which means you won't need to import a certidicate into browsers for your https to work)
Even if you use cloudflare, you should still use a cert @shrewd sand
without one, the traffic between cloudflare and your server is still unencrypted
@brave mantle it's better than nothing.
how
That's interesting that it even says secure then.
"This is definitely secure!" (it's not)
SSL certs are free
use LetsEncrypt
although you probably won't be able to on a simple webhost
sharp think about it this way
the user connects the cloudflare, no one between them can alter the request
cloudflare connects to your server, anyone along the way can alter things about the request, inject things, see things and do other bad stuff
and the user thinks things are all okay because there is an SSL certificate
Anyway to simulate mousemovents in e.g. Selenium that would get picked up by javascript on a website as actual mousemovents, without moving my actual mouse? So I can run multiple scripts at the same time
@rugged abyss you mean in javascript?
No in python, but which will be picked up by Javascript on a website as being a regular mouse
The lib pyautogui
I know that Facebook, Reddit etc tracks movement of your mouse
Because I want to scrape random information from public facebook groups, and if I dont simulate mouse movements they will likely throw me
And at the same time I want more than one script to be running at the same time as I am scraping information for a fairly large project so it would take forever to do with only one
i don't think they will throw you
But it is against rules if you scrape random information from public facebook groups?
and then I would not be able to finish this project in time
Dont think so, as far as I know public data is not illegal to scrape, but they can still ban IPs if they want
so I am looking for something that will simulate mouse movements caught by javascript as regular mouse movements
I'm sorry but I can't help you at breaking rules
but wont actually move my normal mouse so I can have multiple scripts running
There is a easier way to block tracking
as per
I will not share it because you are breaking the rules
I'm not allowed to help you in that case.
This is not breaking rules
you are scraping random information from public facebook groups
To aggregate? What on earth would I do with random peoples personal information, I am interested in average age of various public groups etc and other random metrics for an assignment
I don't know if it is or not against rules.
@kind steppe what do you think? you know this stuff
What
He needs help with scraping random information from public facebook groups.
That's against the rules
I don't think automating facebook is good with facebooks tos
so yeah that probably isn't something one should do
I'm just going to go through the terms
Okay
Okay
https://www.facebook.com/terms.php Section 3, Part 2, Clause 3
Learn more about Facebookโs Terms of Service, which governs your use of Facebook and the products, features, apps, services, technologies, and software we offer.
doesn't facebook have an API you could use?
You may not access or collect data from our Products using automated means (without our prior permission) or attempt to access data that you do not have permission to access.
Yep. So I will not help him.
If you collect the data and have a decent privacy policy, the API can be used,
collecting data through automation of the browser is not allowed
He needs to simulate a fake mouse movement so he will not be tracked
That's against the rules.
I have also shared my password because I needed him to read a file someone sent me, which as per section 3-1 is also not allowed
Not share your password, give access to your Facebook account to others or transfer your account to anyone else (without our permission).
Public data is as per recent rulings in the US eligible to be scraped as long as you do not disrupt the service, please see my previous link
?
share my paqssword with a friend*
What that matters?
point is that ToS are broad and does not cover what is legal/illegal, it is a set of terms that they would like you to follow
Still not a good idea to break it
I highly doubt that anyone will get hurt by me collecting average age and gender information from public groups to use in an assignment for sociology
That is fine
because violating the ToS of a company is not something we permit
However, if you use the API, we can assist
No worries guys I'll figure it out on my own
okay
I can still help you with the mouse tracking part.
But this channel is about web developing
Yeah sorry for not posting it the right place, just was a little in doubt on where it was fitting
You can block the mouse tracking deleting and stopping the js script that is tracking the mouse.
Hmm sounds like a nice idea, I dislike the idea of someone tracking random things I do on the internet anyway
Is it possible to have two apps in a Django project working on the same web page?
absolutely
it's very common to have multiple django apps in the same django project
you usually use the INSTALLED_APPS setting to add dependencies even
anyone know how to profile gunicorn for memory leaks
every time a graph operation is done and the memcache needs updating, the memory usage increases by a few percent
but the memory usage of the actual memcached server does not increase
memory graph for when cache needs updating and when it doesnt
currently my only way of getting memory usage back to normal is restarting gunicorn
ok scrap that cache thing
the increase seems to be completely unpredicatable
after restarting with caching completely disabled (not even imported), this still happens so it can't be a caching issue
I see. You can try using max_requests to recycle workers after a given amount of requests: http://docs.gunicorn.org/en/latest/settings.html#max-requests
hmm is that my only option really?
then i would have to redo my logging system, although it wouldnt be too hard
the 100% cpu (on one core per worker) for 20 secs of restarting a worker is a big deal
20 seconds? when i send TTIN to my master on well, a smaller website, it barely takes two and the cpu is at like 20% at most
i use the sync worker though
my server is a potato
1.3GHz 4 core arm processor
and some HUGE imports
aka the whole dash library
which is massive
ah
well, mine has a single core and 1 GB of memory, so
, but I think there's an option to preload the application which should help with worker boot times: http://docs.gunicorn.org/en/stable/settings.html#preload-app
ooh
that sounds like that might help
By preloading an application you can save some RAM resources as well bonus
that helped hugely with cpu time on start
it didn't make it much faster
but only thrashes one core now
big memory savings too
only idling at 30% ram now
when i set the max requests, what type of request does that account for?
for GET and POST?
that i'm not quite sure about, but i'd guess all requests
damn
that's a problem them
due to the nature of my website (and it's bad coding), a lot of post requests get sent that are very small and the amount of these depends on things like if a user logs in. the only requests that actually cause the memory leak is the graph request, and so if a user logs in, changes a few things and then closes the tab, that might be enough to trigger a worker reset even if no etrxa ram has been used
maybe i can devise some kind of script to send SIGHUP upon high memory usage?
the extra memory uysage is by process
Is there a way to make it so that if a person goes to a certain webpage in flask the .ico file shows that specific item, for exmaple
<link rel="shortcut icon" href="{{ url_for('static', filename='{{weapon}}.ico') }}">
I tried this but it doesn't seem to work.
I've put the .ico file in the static folder, and yes weapon does work because the title of the webpage is working
I just want it so that if they go to /soma then the .ico will be a soma
Alright, so what happens instead?
I get this https://i.mightylordx.tk/9n9nvmfj.png instead of the ico showing up
Does it say anything in the console about it not being found?
No it's only showing me the GET requests from me refreshing the page
i meant your browser sorry
Console is fine but it doesn't seem to be under sources
What is the link to the site?
It's a locally hosted one rn
right
If there is no way to do that I don't mind making only one ico
Well i cant really see a reason why it wouldnt work
which is why i wanted to see the web inspector
I can send my code if that helps
Sure
Sorted :)
Hey guys how does Jinja2 (FLASK) deal with passing arrays of tuples into JS?
does it just turnout as an array with arrays in it, in the JS?
Flask fucking dies, so you have to turn tuples into lists
hey
@native tide It doesn't handle passing anything into js
You need to convert it to json yourself
@brave mantle no you usually dont
It has a templating engine called jinja2
You can literally pass python values into js values
I got it to work by passing a list filled with lists
Which gets rendered into an array of arrays in JS
No you are using jinja2 to render a JavaScript-like variable from python, it is just text, jinja prepares the template and you substitute a value into the JavaScript before it runs, therefore you donโt actually ever touch the JS with jinja
Of course flask will die when you pass in a tuple because you JavaScript does not have tuples, you are passing in a string of the python representation of a tuple but JavaScript does not know how to interpret it
In fact that shouldnโt even kill flask, it is a front end issue, so thatโs probably another error
I don't think you should be using jinja like that. like joseph says, it's just because jinja will generate text that happens to be valid javascript if you make a list of lists and fill it with valuetypes that javascript accepts
like yeah, a list of lists full of strings will be fine
but most python objects will not
what you should do instead is pass a json string to the jinja in the first place.
it'll work if you convert the object to json before you output it to the template
that was the point I was making, yeah
yeah
things "working" coincidentally aren't really a good model for stability
yep. it's a hack. it's an antipattern.
thankfully it's just one extra line of code to pass it in as json
and when you convert to json, it'll change those tuples into arrays for you.
much more consistent
I see fair point, I thought the whole point of a template engine like that in flask was to pass along variables from python to JS etc...
Sup everyone. Trying to set up a webhook and for some reason the SSL certificate I have is not verifying correctly for a third party I'm working with. Absolutely 0 idea on what's going on
Error is this one:
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]
People can connect to the site with no issues through a browser with no SSL cert verification issues(https://dobbybot.com/ , will give you a 404)
Website is Flask via Gunicorn & NGINX
Anyone know what could be happening?
Also: site is down atm
Probably the signing authority doesn't exist in your certificate store
Maybe your python is out of date
So it's not on my end?
No, it is
They're the ones getting the error
Comodo
Oh, that's weird
I don't really recommend comodo but they're definitely a very trusted supplier
Tbf it's the VPS provider that set most of it up for me, but it's Comodo for sure
Brb a sec
Not afaik
So it's a paid cert?
Essentially what's happening here
Is that the certificate signing authority has a provider cert that should be trusted by default by the OS
So the OS can go, hey, they definitely signed this cert, so the cert is good
Right
It sounds like whatever machine this client script is running on is missing that cert
which is weird, because.. comodo
I had to reset the machine a while ago and regenerate the keyfile and stuff
So maybe it's an error on my end
The cert is definitely fine
the cert in the foreground there is the intermediary cert
Ya and the NGINX config looks fine as well as I'm going over it again
as you can see, it's valid
Can you give us your nginx config?
Sure, one sec
https://paste.pydis.com if you need a pastebin
Gonna have to kill the site though as it's in the foreground atm
@brave mantle
There ya go
Sorry bud had to sort something out. And thanks for the help @brave mantle
I'll let them know
Hmm I'm not so sure anymore @brave mantle
Tried accessing the hook from my local machine across the web and got the same error
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='dobbybot.com', port=443): Max retries exceeded with url: /atd/webhook (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
And also
requests.exceptions.SSLError: HTTPSConnectionPool(host='dobbybot.com', port=443): Max retries exceeded with url: /atd/webhook (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
Thanks. I'm reading something about specifying a CABundle file somewhere within my config?
Shouldn't be much longer
Sounds good, thanks again
currently testing for Bleichenbacher..
ah
you have an incomplete certificate chain
head over to https://www.ssllabs.com/ssltest/index.html and type in dobbybot.com
A comprehensive free SSL test for your public web servers.
Hmm aight
so it looks like comodo is supplying you with a set of certs that need to be concatenated
What does that mean and how would I go about doing it?
cat domain_com.crt domain_com.ca-bundle > ssl-bundle.crt
that should be all you need
then use ssl-bundle.crt as your cert
when you're done I'll clear the cache and we'll rescan
Do I need to restart the nginx service? @brave mantle
Aight hold up, it's been a couple months since I checked this out
on a modern distro, it's systemctl reload nginx
yep, centos does have systemd
rescanning
Already on it
Maybe one day I'll understand more than the absolute basics of this stuff
๐
@brave mantle
You need to convert it to json yourself
sorry don't want to interrupt but I really would like to know how to do this correctly, would I json.dumps(pythonList) then pass it through Jinja2 where I would turn the JSON back to an array in the JS?
dumps works, yep
Thank you, even though passing as plain text is aight, hella spaghetti ๐
analysis is complete
Looks the same as before
So to clarify I used the CA-BUNDLE file included in the zip of stuff they let you download
Well, I just got that command from the comodo docs page on working with nginx
Thanks
Ran the error checker and now I'm getting a separate error
SSL_CTX_use_PrivateKey_file("/etc/ssl/www.dobbybot.com.key") failed (SSL: error:0B080074:x509 certificate routines:X509_check_private_key:key values mismatch) nginx: configuration file /etc/nginx/nginx.conf test failed
Has something to do with the CA bundle
Reverted to the old CRT and it's working fine
Aghhh
Aaaaand I fixed it @brave mantle
Wanna know what the issue was?
Using cat didn't put a line break in where one needed to be
So -----END CERTIFICATE----- and -----BEGIN CERTIFICATE----- were on the same line, which NGINX did not like whatsoever
Thanks again for all the help though, appreciate ya
also you can do nginx -t to test config and nginx -s reload to reload
Not sure where I should ask this question, but anyways.
I'm aiming to create a website that "sort of" acts like a refined search engine. Pretty much, the user searches for something, and instead of returning URL's, it's job is to provide the data from a number of sites that a normal google search would bring up.
I know I can easily do this with a python program, but I'm not sure where to start as I want to make it into a website, and I believe embedding python into websites etc is not practical.
Any tips of where I should start, what I need to learn etc would be greatly appreciated, Thanks
Please @ me in your reply.
You could tap into the Google API, to perform the search; then you could pull data from the result sites and generate a page with it using requests and Beautiful Soup, and serve it with Flask.
@wispy lion tagging you as asked, not my response though ^^
Well the problem about creating refined results like you want @wispy lion is that you need to understand what exactly the user is requesting. This requires some type of processing, now you have NLTK and a few others to help, but this is for sure not a very beginner type problem.
Assuming I'm understanding correctly, instead of say googling for "who won the lakers game" you want to return like the actual score of the lakers
@buoyant ledge Yeah pretty much
@pearl kite Thanks
@buoyant ledge, Not sure how exactly NLTK works, but I was thinking more, the user types whatever they want to search, then the website does the search for them, but instead of providing URL'S, it gets the data within. So (if I'm correct in saying that NLTK is used for understanding human language) instead of that <--. It is more basic and will fetch only what the user clearly searched for. So, if it's worded poorly, like any other google search, then the results will be limited as such.
Fair enough
@buoyant ledge Like Lord Greywether would you agree Flask is what I'm looking for?
Flask or Django will do fine. The http framework you use probably wonโt super matter. The logic behind it is gonna be the key
Aight, thanks
Hey guys, I'm using VSCode to go through Django tutorial i found and I'm getting errors on line
<div class="row pt-3" onclick="window.location='{% url 'detail' product.id %}';" style="cursor: pointer;">
';' expected.
code works fine on webpage so i suppose this is some false error detection
any idea how to make VSCode to ignore it?
#python #django
hello people, this is my first post in here so be nice !
I'm looking for interesting django, python recruitment question for very advanced developer. Can some of you help ?
Hi @native tide, welcome to the server! This channel is more for web development questions. Until we get an actual jobs channel, you might be better off in one of the Off Topic channels!
Hi @pearl kite Ok thanks ๐
Currently trying to figure out the following: trying to automate generating a HTTPS certificate with nginx and certbot. I need to first add the HTTP configuration necessary to serve the challenge, and then I need to add the HTTPS configuration. I see two possibilities: Separating the HTTP and HTTPS configs in two files (e.g. sites-available/http/example.com.conf and sites-available/https/example.com.conf) or first adding a file with only the HTTP config and after getting the certificate replacing it with the fully fledged config. What's better?
Or maybe there's a better naming scheme for HTTP and HTTPS vhosts?
Also, what are some common practices for naming site configs?
it works, but it doesn't if you dont have your cert yet
i want to automate the entire process
went with two separated configs
can I ask why?
don't have anything to do right now :P
certbot already renews them for you. why automate such a trivial thing
Renewal isn't the issue, but the initial retrieval is
๐
Works for me @meager anchor
Even without the certs
Maybe your nginx is out of date
Pretty sure nginx errors if you give it a cert that isn't present
$ sudo nginx -t
nginx: [emerg] BIO_new_file("/etc/letsencrypt/live/baconlabs.ca/ggggfullchain.pem") failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/letsencrypt/live/baconlabs.ca/ggggfullchain.pem','r') error:2006D080:BIO routines:BIO_new_file:no such file)
nginx: configuration file /etc/nginx/nginx.conf test failed
1.14.0
so you changed the cert path in an enabled vhost and nginx -t doesn't complain?
nginx -t isn't for reloading
It's for testing, yes
I guess nginx errors when you visit the HTTPS page then, though?
Yeah, the test fails, but nginx still reloads
I see
It must be working because otherwise I wouldn't be able to get my certs
Gotta cook, afk
you didn't
what is the best way to deploy your django project on VPS like Digital Ocean?
Install nginx, set up your app with gunicorn, create a systemd service file for running it through gunicorn (and the yourproject.wsgi) module, and then in nginx, use ```nginx
server {
# ...
location / {
proxy_pass http://localhost:5000;
}
}
where `5000` is the port that gunicorn listens on
alternatively you can use a unix socket
digitalocean probably has a guide for this..
Python has a base64 module
>>> import base64
>>> base64.b64encode(b"Hello world")
b'SGVsbG8gd29ybGQ='
>>> base64.b64decode(b'SGVsbG8gd29ybGQ=')
b'Hello world'
You do need to pass in the arguments as bytes instead of str's though though
could i then send it as an image?
Could you explain what you are trying to do?
oh nm i've just reallised something
im developing a telegram bot
it requires a path to be passed through for images
i need to save it in order for that to work
hmm
It is probably possible
if you could provide me with the documentation for the library I can take a look
Also
this is not really a web development related subject
oh
i wasn't really sure where to put it
i thought so because of base64 and stuff
where would this belong?
anyone here can help me with setting up a production server for flask?
debian VM on azure, tried webapp first but that doesnt support python 3.7
i did read something about wsgi but ouldnt really get it up and running
You could use gunicorn as your wsgi server
Or go one step further and use gunicorn + nginx as reverse proxy
But gunicorn standalone should be enough
It's really not hard
I use nginx and uwsgi for my Django server. It took a bit to setup but thereโs a ton of documentation on it
it's recommended to use gunicorn behind a reverse proxy though
and the website itself reads strongly advise you to use nginx.
why should i use reverse proxy?
To try and limit dos attacks I suppose
It's a separation of both concerns and jobs
Nginx is far better at serving static files than your webapp is
Also, gunicorn will generally have a pool of workers that nginx will have to load balance over instead of just a single socket
gunicorn doesn't support http2 either: https://github.com/benoitc/gunicorn/issues/1195
@meager anchor thank You for answering about deploy, i just have one question if i would like to edit code on my PC and sync changes with VPS that have my project deployed on - what are my options?
in tutorial i just finished guy was using git and github for that
You could use a so called webhook from github to your server but that's a story for #414737889352744971
@gritty carbon
@gritty carbon i actually need to set up same thing, to automatically pull my latst commits to dev server
i don't even need to make it acutomatically ๐
If you've got questions around automating parts of your workflow #414737889352744971 is always a good place to ask
ok , thank you ๐
a dumb script doing git pull, pipenv install, pipenv run python manage.py migrate, pipenv run python manage.py collectstatic --noinput and then restarting the gunicorn service would probably do the trick, but that's probably not a good idea
from flask import Flask, request
import json
import os
app = Flask(__name__)
@app.route('/deploy', methods=['POST'])
def deploy():
data = request.data
content = request.get_json()
if request.headers.get('X-GitHub-Event') == "push":
payload = request.get_json()
print(payload['refs'])
if payload['refs'] == "refs/heads/master":
print("Master Push")
with open('data.json', 'w') as outfile:
json.dump(content, outfile)
return ""
if __name__ == '__main__':
app.run(host= '0.0.0.0')
lets see if i can get the correct webhook event
i would add some authorization to that
from flask import Flask, request
import json
import subprocess
import os
app = Flask(__name__)
@app.route('/deploy', methods=['POST'])
def deploy():
data = request.data
content = request.get_json()
if request.headers.get('X-GitHub-Event') == "push":
payload = request.get_json()
print(payload['ref'])
if payload['ref'] == "refs/heads/master":
print("Master Push")
try:
cmd_output = subprocess.check_output(
["git", "-C", "/var/www/dev", "pull"],)
print(cmd_output)
except subprocess.CalledProcessError as error:
return jsonify({'msg': str(error.output)})
return ""
if __name__ == '__main__':
app.run(host= '0.0.0.0')
this is a early test, auth coming after i know i can actually do it this way
๐
okay, it does work, time to add auth token
ok maybe this will be the little bit more secure version
from flask import Flask, request, jsonify
import json
import subprocess
import os
import hmac
import hashlib
app = Flask(__name__)
def verify_hmac_hash(data, signature):
github_secret = bytes(os.environ['GITHUB_SECRET'], 'UTF-8')
mac = hmac.new(github_secret, msg=data, digestmod=hashlib.sha1)
return hmac.compare_digest('sha1=' + mac.hexdigest(), signature)
@app.route('/deploy', methods=['POST'])
def deploy():
signature = request.headers.get('X-Hub-Signature')
data = request.data
if verify_hmac_hash(data, signature):
if request.headers.get('X-GitHub-Event') == "push":
payload = request.get_json()
print(payload['ref'])
if payload['ref'] == "refs/heads/master":
print("Master Push")
try:
cmd_output = subprocess.check_output(
["git", "-C", "/var/www/dev", "pull"],)
print(cmd_output)
except subprocess.CalledProcessError as error:
return jsonify({'msg': str(error.output)})
return ""
if __name__ == '__main__':
app.run(host= '0.0.0.0')
aaand it works
good stuff ๐
i've actually been wondering what the best way to autodeploy successfull branches might be
now to figure out how i can make this run commands to stop the webserver and restart it, its gunicorn nginx reverse proxy, as was suggested
some commands require root
but i dont want to run the whole script as root
you don't need to restart gunicorn, you can tell it to reload and it will gracefully stop and start new workers, IIRC
hmm, i have it set as a service
I'm not fully sure myself and it's something i'm also currently trying to figure out
Might be good to post in #414737889352744971 instead
Can someone tell me what this site is using for the UI, its so cool : http://www.zelaacoin.com
ZelaaCoin is a cryptocurrency project which is mainstreaming an ecosystem and making it a convergence for other cryptocurrencies to develop on our products and utilise mass adoption through our channels
Looks like it was made by softnio
Hmm
someone help me?
I have a little problem with the flask
but, google and starckoverflow no help me.
What's the problem?
I have a flask script to run it as a service, when I opened the exe, it works manually, but when I start it with the service it does not respond to requests.
I use pyinstaller to generate the exe with these parameters --onefile --windowed
So it works on it's own when you run it, but it doesn't work when the service starts it?
I can not install anything, more than a service as executable, I'm limited
ok
"So it works on it's own when you run it, but it doesn't work when the service starts it?(edited) "
exactly
So, does the service keep running after main(self) returns?
If it doesn't, then the flask server would also stop running
Also, have you made sure serviceweb.exe is getting started and is running?
(Look in task manager maybe)
Yes, I do, but it's not there
I've done it before, but not with flask, maybe it's the output generated by flask when starting?
maybe
if i have api endpoint like http://127.0.0.1:8000/api/key/<key>
is there a way to redirect users from that page if they visit it in the web broswer for whatever reason
yp
yp
yep
<meta http-equiv="refresh" content="0; url=http://example.com/" />
return "<meta http-equiv="refresh" content="0; url=http://example.com/" />"
the api returns that if someone visits from a browser?
will the visit be from the browser?
yea i do not want people sitting on that page if they visit it from there, i want to redirect them back to the index
im fine with api calls from clients, just dont need anyone visiting the page since there isnt anything there
one second
Sorry I couldn't be more helpful, not experienced with Flask
alright ill look into it thanks
@potent nebula for your pyinstaller question are you sure the service is finding and starting the .exe correctly?
@potent nebula @granite wigeon isn't it better to return a response with Flask's redirect function rather than a raw meta tag?
In trying to link a button to another page and every time I press the button I get method not allowed, I have my method set to get and post,
can you show your code, Fear of God?
@queen needle i tried to do that but it was ignored
i made a view just for redirecting anyone that lands on the api page but maybe i missed something
url_for?
def redirectapi():
return redirect(url_for('views.index'))```
@queen needle
the route would be http://127.0.0.1:8000/api/key/keycodeishere
That looks like it should work... But I'm also just coming back home and I'm tired ๐
What does it return anyway? Is the raw source completely blank or what does it do?
returns json info if i have the api unprotected
So not a Flask error
Tbh that endpoint looks so simple that I can't find a hole. It should return a 302 towards the url for views.index
However, if that's an api endpoint and not a web page, whatever you're using as a client should also handle that 302
yea its an api endpoint
so i should return a 302 via the api when the content type is text/html?
Um, if the content type is text/html (aka you're displaying an html page to a browser) then return redirect is how it's done
If you're trying to redirect a REST client with application/json, then the http response code should be 302 and your json should include the url... I dunno what the standard is in that case though
So you should return jsonify({stuff including the redirect url}), 302 I think
ill give that a try real quick
However: redirects in REST api do no make much sense usually
i just didnt want people visiting the rest api endpoint from the browser and sitting on the page, id if i have to redirect from something like ngix or if i should just get over it
I cannot really find a standard for this. The Q&As I've found usually tell that you should configure your web server to rewrite the url
yea i couldnt find much for it either
I think you should just ignore it
There is nothing preventing a user from doing a GET on a rest api
yea ill do that for now and once i get the actual server up and running and not the flask server ill look into it again maybe
thanks for the help
Normally if you have some kind of authorisation for that api, you won't have to worry
yea i will set up one with jwt tokens
@granite wigeon you can do something by checking user-agent and http_x_requested_with maybe...
But all that stuff can be spoofed
It's pointless imho, if a user wants to call your rest api with a browser they should be allowed to
If you have oauth2 you'll be fine anyway
yea i agree it was just a minor thing that i got distracted with last night
does this
{{form.developer.label(class_="btn details btn-primary") {{form.developer}} }}
output something like
<label class="btn details btn-primary" style="margin-left:1px;margin-right:1px;">Developer
<input type="checkbox">
</label>
Hehe I understand, it's good to be curious about it anyway. Flask can do a lot of things once you start using your own response/request classes
@keen ore if that's jinja, I don't think you can nest tags
hmm
But the answer is to try
๐
If you'd allow me a comment, though
Why not use <label for="your_input">?
You needn't nest input inside your label
the label is used more to make the
those are checkboxes
well the checkbox is invisible as the label is used to make the look
I see, a button-group?
?
Are you using bootstrap?
yes
Ye I was checking it and it's indeed putting the input inside labels
Honestly I'd just type out the label tags
You can access the label title from the field attribute
I'm trying to look whether there's a way you can do it...
im making this in a way that i need to touch the html as little as possible after launching so that all text can be edited on configs
You could write a jinja2 macro that does it for you
