#web-development

2 messages ยท Page 10 of 1

keen ore
#

make sure to force refresh

quick scarab
#

yeah

#

this is actually driving me insane

#

it's gonna be the smallest detail

#

i've been looking for like an hour now

keen ore
#

for me that works on chrome with the !important

quick scarab
#

hmm

#

maybe it's something to do with my python??

#

what is the href for your css?

keen ore
#

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

quick scarab
#

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?

keen ore
#

?

#

why is there php?

#

are you using flask?

quick scarab
#

uh huh

keen ore
#

try

    <div class="container" id="wrapper" style="background-color: #ff6600">
            <p id="loginforminfo"> Login to continue to the site: </p>

    </div>
quick scarab
#

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

keen ore
#

hmm

#

maybe something else tries to override the background color

quick scarab
#

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?

keen ore
#

not sure

quick scarab
#

finally got it to work!! thanks so much for your help ๐Ÿ˜Š

keen ore
#

๐Ÿ‘

loud walrus
#

does django/flask have angular support?

brave mantle
#

angular has nothing to do with the server

loud walrus
#

but like

brave mantle
#

it's client-side javascript

loud walrus
#

right

#

if the user presses a button

#

how can I pass that action from angular to flask

#

if that makes sense?

brave mantle
#

that's really going to be up to you

#

I don't recommend angular for that though

#

that's massively overkill

loud walrus
#

wdym

brave mantle
#

you should be able to do it with nothing but javascript itself

loud walrus
#

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?

brave mantle
#

yep

loud walrus
#

lol

loud walrus
#

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

rugged abyss
#

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?

loud walrus
#

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.

loud walrus
#
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

native tide
#

hello

#

i need help with my apache server

cyan pilot
#

bot.tags.get('ask')

lavish prismBOT
#
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.

native tide
#

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

native tide
#

patience 100

#

I want the domain to display in the hotbar and not the ip

buoyant ledge
#

So when you visit the domain does it currently bring you to the server but displays the IP and not the name?

native tide
#

its fine now mate fixed it with some Advanced DNS adjustments

sour heath
#

ValueError: unexpected '{' in field name

#

I later format some things

#

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 $

native tide
#

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.

sour heath
#

it has to be those curly brackedtgs

#

brackets

#

seen as formatting brackets

#

if you mean the $ char issue, I have no idea

sour heath
#

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

sour heath
#

haHA I got it

#

had to make an external js file though

loud walrus
#

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?

sour heath
#

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

native tide
#

you either need to define new delimiters, square brackets is a good choice, for vue or escape with {% raw %} {{ whatever }} {% endraw %}

loud walrus
#

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?

deep cave
#

probably can't resolve the path.

meager anchor
#

you wrote your JS stuff into the HTML code at your earlier question

#

use <script>

gentle sapphire
#

@warm pumice do you have post set up in your view as well?

warm pumice
#

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

gentle sapphire
#

yes, it is

warm pumice
#

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?

gentle sapphire
#

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

warm pumice
#

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

gentle sapphire
#

glad it worked

loud walrus
#

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

lusty rapids
#

Anyone here able to help with deploying a celery/flask/rediscloud app to heroku? running into an error idk how to solve.

sour heath
#

How exactly do websites connect two players within a game or some other creation

jagged knot
#

need some scrapy guides

loud walrus
#

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

sour heath
#

people are saying to use sockets

loud walrus
#

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

sour heath
#

its a one on one card game

lusty rapids
#

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

native tide
cobalt vale
#

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?

brave mantle
#

@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

cobalt vale
#

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

brave mantle
#

You won't really find an example for that

#

It's the kind of thing that entirely depends on your application

cobalt vale
#

Yeah, true..

brave mantle
#

You'll need to be sure you're experienced in python before tackling more than a simple script

cobalt vale
#

True, ah well, I'll just start at the beginning of the code again, it is not that big

#

thanks anyway

cobalt vale
#

@brave mantle Can you maybe point me to a deathbycaptcha guide for Selenium?

brave mantle
#

You're looking to solve captchas with selenium?

#

The only real way to do that is, well, manually

cobalt vale
#

via the deathbycaptcha api

brave mantle
#

ah, well I've never even heard of that

cobalt vale
#

Really? damn..

#

Hmm, ok

brave mantle
#

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

cobalt vale
#

Sure but then I'm not able to do any automations online

#

I'll ask elsewhere, thanks anyway

heady veldt
#

im failing to check the checkbox
tried every div but im getting always element not visible when using .click()
anyone got an idea?

queen fiber
#

anyone has any idea if there's a limit to scrapy crawl speed. I can only scrape 500pages/s on my computer

queen needle
#

@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...

queen fiber
#

oh sorry i though this was the right category

queen needle
#

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:

  1. Ask the user for his email, and find out which IDP he belongs to [black box]
  2. Send the user to the IDP's login page and make him sign in
  3. The AS needs to check if the user is authorised to use the WA
  4. 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?

hard lagoon
#

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?

polar wasp
#

@hard lagoon what's the first line of your file that uses bs4

#

(i.e. when you're actually initializing the bs4 object)

hard lagoon
#

dont worry, i fixed it

#

but thanks anyway

loud walrus
#

hey

quiet ridge
#

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.

brave mantle
#

Yep, those are the two I'd recommend

loud walrus
#

well

#

prefer django @quiet ridge

#

but thats me

meager anchor
#

maybe include some practical reasons as to why

quiet ridge
#

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 ! ๐Ÿ˜„

loud walrus
#

@meager anchor

#

completely not related to python

#

but any idea how to create a canvas which takes the entire screen in p5.js?

native tide
#

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)

vague seal
#

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!

quartz maple
#

flask or django

#

django pays more

#

@brave mantle

brave mantle
#

don't make your decision based on that

#

just try them and see what you like

quartz maple
#

whats better?

#

and @brave mantle sorry to bother you but i am touching up on python.

#

and wheres a good place to do so?

brave mantle
#

Neither is "better"

#

they're just different lol

quartz maple
#

when i say touching up

#

i mean rebuilding what i know

#

could you do a quiz for me? @brave mantle

brave mantle
#

Not sure what you mean

native tide
#

How to shuffle a string (such as "asiuc90m2u34c092u") pseudorandomly in javascript?

#

With a given string

#

Nevermind.

summer dirge
#

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
native tide
#

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

summer dirge
#

i personally am never calling getattr(...)

#

its called in \Python37\lib\site-packages\flask_login\utils.py

#

you can see that in the stacktrace

polar wasp
#

what is your user object and your login manager object?

#

and are you able to see what current_app.login_manager.id_attribute is?

queen needle
#

@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.

marsh canyon
#

help plz

native tide
#

do the comments have a class for themselves?

#

you may want to give them a class for easier styling

marsh canyon
#

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

native tide
#

idk that footer(?) seems to get a background color ๐Ÿค”

marsh canyon
#

the font-weight works

#

footer got its own css

native tide
#

yea, so why shouldn't the comments have their own css (class)

marsh canyon
#

the whole webpage

#

the eniter white background u see

#

i want it filled with another color

#

but its not geting filled

native tide
#

did you already try just background: grey;

#

?

marsh canyon
#

nop dosent work with background also

native tide
#

* instead of body?

#

nah, i mean the rest is already affected, but still worth a shot i guess

marsh canyon
#

the other webpages work with background-color,wondering whats wrong with this one

thorny hill
#

is Flask more toward SPA (react angular) ?

#

compared to django

native tide
#

iirc flask is more like express

thorny hill
#

flask to build rest ?

#

only the backend ?

#

the front in React or Angular ?

native tide
#

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

thorny hill
#

django its full stack and Flask is backend ?

native tide
#

django is full stack out of the box yes

marsh canyon
#

@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

native tide
#

with flask you'd need to add stuff like a database and frontend template engine

#

@marsh canyon ok

marsh canyon
#

@native tide

#

the background color is not being executed in comments.html and also view-comments.html

native tide
#

shouldn't frameworks be loaded before the custom css though?

#

just in general

marsh canyon
#

well btw the bootstrap is being used in that

#

there is not bootstrap

native tide
marsh canyon
#

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

native tide
#
      <br>
      <br>
      <br>
      <br>
#

that's why divs, css classes and padding exists D:

marsh canyon
#

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

summer dirge
#

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
rain finch
#

what's in you guys opinion the most optimal way to make your usual user management / data CRUDS app for a customer ?

queen needle
#

@summer dirge could the User class be trying to use id as a mixin class?

#

bot.docs['id']

lavish prismBOT
#
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.
summer dirge
#

i want to punch my face so bad rn but that would hrt

#

that was it

#

apparently i tried somethin

#

and never reverted it

queen needle
#

Ye, it's trying to subclass the builtin id() function... Which is also an object ๐Ÿ˜…

summer dirge
#

it was trying to subcalss both

#

wel

queen needle
#

I don't blame you, metaclass-related exceptions are always hard to decipher

summer dirge
#

ye

#

anyways

#

THANK YOU

queen needle
#

You're very welcome

#

๐Ÿ‘Œ

#

@rain finch and I don't understand the question ๐Ÿ˜ข

jagged knot
#

has anyone used the dyanmic django scraper app? any feedback?

native tide
#

@marsh canyon weird question, but have you tried putting the color in quotes?

native tide
#

currently thinking about doing something with it

#

I'm wondering how it would work with websockets performance wise

rain finch
#

Sorry I was asking what framework(s) do you guys use for building admin cruds easily lol

queen needle
#

Both Django and flask have good admin cruds

quartz maple
#

@queen needle that looks to me that Django is better

jagged knot
#

I think Django is better for more experience web dev

queen needle
#

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.

quartz maple
#

which is easest to learn @queen needle

feral dragon
#

Both aren't too bad, but Flask might be easier @quartz maple

deep cave
#

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.

quartz maple
#

@deep cave i want to make a eCommerce Website

#

thats fully custom

#

and

#

it sells digital keys

deep cave
#

sounds like a good fifth project

#

what are you gonna do for your first four?

queen needle
#

Sounds like a Django project to me

#

(of course this doesn't mean Flask is a bad fit for it)

deep cave
#

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.

queen needle
#

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

quartz maple
#

itd be hosted locally

#

then on a server

queen needle
#

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

quartz maple
#

people cant touch it locally

#

lol

queen needle
#

So it's a toy project

#

Go wild then ๐Ÿ˜

#

I'm sure there are tutorials out there. I'd recommend Django in your case

quartz maple
#

itd say no one can touch it locally?

#

unless they forced there way in

queen needle
#

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

quartz maple
#

i mean even if i did share the IP

#

itd shut it down

queen needle
#

Do you know what a port is?

quartz maple
#

yes.....

#

i was just about to say

#

itd bind it to a different one

queen needle
#

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

quartz maple
#

or not have it on the default in the first place.

queen needle
#

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

brave mantle
#

It should be on one of the standard ports

#

Otherwise people will need the port too

queen needle
#

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)

keen ore
#

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

native tide
#

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

fast saddle
#

hey

#

how do i make the site change based off of what the user puts in the url?

keen ore
#

flask? django?

fast saddle
#

falask

#

flask

keen ore
#

also, remember to NEVER include private/sensitive data in a GET request

fast saddle
#

yes

keen ore
#
@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

eternal thunder
#

Hey

#

What would be the best way to collect stats using Sanic?

#

Its p much async flask

#

I want to collect stats like

meager anchor
#

except it's insecure

eternal thunder
#

Amount of requests

#

Requests per second 'n shit

meager anchor
#

you can use middleware i think

#

i really wouldn't recommend using sanic though

#

just use flask with gevent if you want async flask

eternal thunder
#

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

meager anchor
#

this looks like what you want

eternal thunder
#

will look into it

#

Well, my issue is storing it

#

How do I efficiently store stats like that

eternal thunder
#

@meager anchor

native tide
#

where do you guys format time+timezones, on the frontend or backend?

native tide
#

it seems I'm supposed to do this on the frontend

deep cave
#

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

kind steppe
#

timezone format is best on frontend because it can then adapt to local time settings

deep cave
#

yep

kind steppe
#

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

deep cave
#

Moment Timezone allows you to do anything timezoney, too

native tide
#

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

deep cave
#

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

tame viper
#

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

native tide
#

@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

sacred perch
#

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

weak lotus
#

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 ' ?

sour heath
#

How exactly can I have a python file load into the html so it can be accessed by javascripts

#

using like ajax or something

unreal dagger
#

Do django questions go here?

native tide
#

Yep, if they are about the web framework @unreal dagger

#

Also, how to get the text after ? in a url as string in js?

deft star
#

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)

shrewd sand
#

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

little nexus
#

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)

brave mantle
#

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

shrewd sand
#

@brave mantle it's better than nothing.

brave mantle
#

No, it's really not

#

it's arguably worse than nothing

shrewd sand
#

how

brave mantle
#

because you're telling your user they're secure when they're not

#

brb

shrewd sand
#

That's interesting that it even says secure then.

native tide
#

"This is definitely secure!" (it's not)

shrewd sand
#

I don't want to pay the money tho

#

For a SSL certificate :(

brave mantle
#

SSL certs are free

#

use LetsEncrypt

#

although you probably won't be able to on a simple webhost

kind steppe
#

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

rugged abyss
#

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

native tide
#

@rugged abyss you mean in javascript?

rugged abyss
#

No in python, but which will be picked up by Javascript on a website as being a regular mouse

native tide
#

The lib pyautogui

rugged abyss
#

I know that Facebook, Reddit etc tracks movement of your mouse

native tide
#

Um...

#

and what matters if traks movement?

rugged abyss
#

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

native tide
#

i don't think they will throw you

#

But it is against rules if you scrape random information from public facebook groups?

rugged abyss
#

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

native tide
#

I'm sorry but I can't help you at breaking rules

rugged abyss
#

but wont actually move my normal mouse so I can have multiple scripts running

native tide
#

There is a easier way to block tracking

rugged abyss
#

as per

native tide
#

I will not share it because you are breaking the rules

#

I'm not allowed to help you in that case.

rugged abyss
#

This is not breaking rules

native tide
#

you are scraping random information from public facebook groups

rugged abyss
#

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

native tide
#

I don't know if it is or not against rules.

#

@kind steppe what do you think? you know this stuff

kind steppe
#

What

native tide
#

He needs help with scraping random information from public facebook groups.

#

That's against the rules

kind steppe
#

I don't think automating facebook is good with facebooks tos

#

so yeah that probably isn't something one should do

native tide
#

Yeah...

#

Should I help him?

kind steppe
#

I'm just going to go through the terms

native tide
#

Okay

kind steppe
#

Okay

#

https://www.facebook.com/terms.php Section 3, Part 2, Clause 3

deep cave
#

doesn't facebook have an API you could use?

kind steppe
#
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.
native tide
#

Yep. So I will not help him.

kind steppe
#

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

native tide
#

He needs to simulate a fake mouse movement so he will not be tracked

#

That's against the rules.

rugged abyss
#

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

native tide
#

?

rugged abyss
#

share my paqssword with a friend*

native tide
#

What that matters?

rugged abyss
#

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

native tide
#

Still not a good idea to break it

rugged abyss
#

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

kind steppe
#

We aren't saying you are breaking the law

#

We are saying we will not help you at all

rugged abyss
#

That is fine

kind steppe
#

because violating the ToS of a company is not something we permit

#

However, if you use the API, we can assist

native tide
#

yeah, read the documentation. don't scrape

#

maybe it will be easier

rugged abyss
#

No worries guys I'll figure it out on my own

native tide
#

okay

#

I can still help you with the mouse tracking part.

#

But this channel is about web developing

rugged abyss
#

Yeah sorry for not posting it the right place, just was a little in doubt on where it was fitting

native tide
#

You can block the mouse tracking deleting and stopping the js script that is tracking the mouse.

rugged abyss
#

Hmm sounds like a nice idea, I dislike the idea of someone tracking random things I do on the internet anyway

unreal dagger
#

Is it possible to have two apps in a Django project working on the same web page?

meager anchor
#

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

little nexus
#

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

#

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

meager anchor
#

hmm

#

are you recycling your workers?

little nexus
#

im on the latest 19.9 gunicorn

meager anchor
little nexus
#

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

meager anchor
#

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

little nexus
#

my server is a potato

#

1.3GHz 4 core arm processor

#

and some HUGE imports

#

aka the whole dash library

#

which is massive

meager anchor
#

ah

little nexus
#

and 2GB total memory

#

which is why this is such a big probelm XD

meager anchor
little nexus
#

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

#

only idling at 30% ram now

#

when i set the max requests, what type of request does that account for?

#

for GET and POST?

meager anchor
#

that i'm not quite sure about, but i'd guess all requests

little nexus
#

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?

fossil lotus
#

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.

mental chasm
#

is weapon defined different for each person?

#

And what didnt work about it?

fossil lotus
#

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

mental chasm
#

Alright, so what happens instead?

fossil lotus
mental chasm
#

Does it say anything in the console about it not being found?

fossil lotus
#

No it's only showing me the GET requests from me refreshing the page

mental chasm
#

i meant your browser sorry

fossil lotus
#

Console is fine but it doesn't seem to be under sources

mental chasm
#

What is the link to the site?

fossil lotus
#

It's a locally hosted one rn

mental chasm
#

right

fossil lotus
#

If there is no way to do that I don't mind making only one ico

mental chasm
#

Well i cant really see a reason why it wouldnt work

#

which is why i wanted to see the web inspector

fossil lotus
#

I can send my code if that helps

mental chasm
#

Sure

mental chasm
#

Sorted :)

native tide
#

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?

native tide
#

Flask fucking dies, so you have to turn tuples into lists

topaz bluff
#

hey

brave mantle
#

@native tide It doesn't handle passing anything into js

#

You need to convert it to json yourself

native tide
#

@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

kind steppe
#

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

deep cave
#

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.

brave mantle
#

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

deep cave
#

yeah

brave mantle
#

things "working" coincidentally aren't really a good model for stability

deep cave
#

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

native tide
#

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...

dry portal
#

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

brave mantle
#

Probably the signing authority doesn't exist in your certificate store

#

Maybe your python is out of date

dry portal
#

So it's not on my end?

brave mantle
#

No, it is

dry portal
#

They're the ones getting the error

brave mantle
#

Oh right

#

Well what company do you sign with? Let's encrypt?

dry portal
#

Comodo

brave mantle
#

Oh, that's weird

#

I don't really recommend comodo but they're definitely a very trusted supplier

dry portal
#

Tbf it's the VPS provider that set most of it up for me, but it's Comodo for sure

brave mantle
#

Brb a sec

dry portal
#

Aight

brave mantle
#

Yeah, I tried and it works

#

Did you use their startssl thing?

dry portal
#

Not afaik

brave mantle
#

So it's a paid cert?

dry portal
#

Yup

#

I work at the provider's sister company so got it all on the cheap

brave mantle
#

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

dry portal
#

Right

brave mantle
#

It sounds like whatever machine this client script is running on is missing that cert

#

which is weird, because.. comodo

dry portal
#

I had to reset the machine a while ago and regenerate the keyfile and stuff

#

So maybe it's an error on my end

brave mantle
#

The cert is definitely fine

#

the cert in the foreground there is the intermediary cert

dry portal
#

Ya and the NGINX config looks fine as well as I'm going over it again

brave mantle
#

as you can see, it's valid

dry portal
#

Hmm

#

Could it have something to do with the request type?

brave mantle
#

No, that shouldn't matter

#

it's a protocol-level thing

dry portal
#

Basically they're trying to post me a json with stats

#

Hmm alright

brave mantle
#

Can you give us your nginx config?

dry portal
#

Sure, one sec

brave mantle
dry portal
#

Gonna have to kill the site though as it's in the foreground atm

#

@brave mantle

#

There ya go

brave mantle
#

yeah that looks fine @dry portal

#

I don't really think this is your problem

dry portal
#

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')],)",),))

brave mantle
#

hmm

#

@dry portal I'm running an SSL analysis now

dry portal
#

Thanks. I'm reading something about specifying a CABundle file somewhere within my config?

brave mantle
#

Shouldn't be much longer

dry portal
#

Sounds good, thanks again

brave mantle
#

currently testing for Bleichenbacher..

#

ah

#

you have an incomplete certificate chain

dry portal
#

Hmm aight

brave mantle
#

so it looks like comodo is supplying you with a set of certs that need to be concatenated

dry portal
#

What does that mean and how would I go about doing it?

brave mantle
#

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

dry portal
#

And then use... roger that

#

Lemme give it a whirl

brave mantle
#

when you're done I'll clear the cache and we'll rescan

dry portal
#

Do I need to restart the nginx service? @brave mantle

brave mantle
#

What're you on, debian?

#

You can reload it

#

instead of restart it

dry portal
#

Aight hold up, it's been a couple months since I checked this out

brave mantle
#

on a modern distro, it's systemctl reload nginx

dry portal
#

That probs workedยด

#

Running CentOS 7 atm

brave mantle
#

yep, centos does have systemd

dry portal
#

Site should be up again

#

Yup, cert is valid on browser

brave mantle
#

rescanning

dry portal
#

Already on it

#

Maybe one day I'll understand more than the absolute basics of this stuff

#

๐Ÿ˜›

native tide
#

@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?

brave mantle
#

dumps works, yep

native tide
#

Thank you, even though passing as plain text is aight, hella spaghetti ๐Ÿ˜„

dry portal
#

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

brave mantle
#

Well, I just got that command from the comodo docs page on working with nginx

dry portal
#

Also still getting an error from requests.post()

#

And hmm

dry portal
#

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

little nexus
#

also you can do nginx -t to test config and nginx -s reload to reload

wispy lion
#

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.

pearl kite
#

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.

little nexus
#

@wispy lion tagging you as asked, not my response though ^^

buoyant ledge
#

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

wispy lion
#

@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.

buoyant ledge
#

Fair enough

wispy lion
#

@buoyant ledge Like Lord Greywether would you agree Flask is what I'm looking for?

buoyant ledge
#

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

wispy lion
#

Aight, thanks

gritty carbon
#

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?

native tide
#

#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 ?

pearl kite
#

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!

native tide
#

Hi @pearl kite Ok thanks ๐Ÿ˜ƒ

meager anchor
#

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?

brave mantle
#

I have both server blocks in a single file

#

It just works.

meager anchor
#

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

deep cave
#

can I ask why?

meager anchor
#

don't have anything to do right now :P

deep cave
#

certbot already renews them for you. why automate such a trivial thing

meager anchor
#

Renewal isn't the issue, but the initial retrieval is

deep cave
#

yeah but that's a one-time thing :D

#

anyway okay

#

carry on

meager anchor
#

๐Ÿ‘Œ

brave mantle
#

Works for me @meager anchor

#

Even without the certs

#

Maybe your nginx is out of date

meager anchor
#

Pretty sure nginx errors if you give it a cert that isn't present

brave mantle
#

Nope, mine doesn't even complain

#

I think it used to, but mine doesn't.

meager anchor
#
$ 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

brave mantle
#

Well I'm not at my machine

#

Sec

#

1.14.0

meager anchor
#

so you changed the cert path in an enabled vhost and nginx -t doesn't complain?

brave mantle
#

I don't reload with nginx -t

#

I reload with systemctl reload nginx

meager anchor
#

nginx -t isn't for reloading

brave mantle
#

It's for testing, yes

meager anchor
#

I guess nginx errors when you visit the HTTPS page then, though?

brave mantle
#

Yeah, the test fails, but nginx still reloads

meager anchor
#

I see

brave mantle
#

It must be working because otherwise I wouldn't be able to get my certs

#

Gotta cook, afk

meager anchor
#

๐Ÿ‘

#

my nginx doesn't reload with invalid cert paths either

little nexus
#

nginx -t does not reload

#

just runs a test on config

#

ngins -s reload reloads

meager anchor
#

and where did i imply that it did

#

๐Ÿค”

little nexus
#

you didn't

gritty carbon
#

what is the best way to deploy your django project on VPS like Digital Ocean?

meager anchor
#

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..

deep cave
#

seconding this method.

#

excellent way to do it.

native tide
#

hey

#

i was wondering, is it possible to decode base64 without saving it to file?

kind steppe
#

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

native tide
#

could i then send it as an image?

kind steppe
#

Could you explain what you are trying to do?

native tide
#

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

kind steppe
#

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

native tide
#

oh

#

i wasn't really sure where to put it

#

i thought so because of base64 and stuff

#

where would this belong?

kind steppe
#

I'll just find a free channel one second

keen ore
#

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

strange thorn
#

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

buoyant ledge
#

I use nginx and uwsgi for my Django server. It took a bit to setup but thereโ€™s a ton of documentation on it

meager anchor
#

it's recommended to use gunicorn behind a reverse proxy though

#

and the website itself reads strongly advise you to use nginx.

keen ore
#

why should i use reverse proxy?

jade egret
#

To try and limit dos attacks I suppose

brave mantle
#

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

meager anchor
gritty carbon
#

@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

strange thorn
#

You could use a so called webhook from github to your server but that's a story for #414737889352744971

#

@gritty carbon

keen ore
#

@gritty carbon i actually need to set up same thing, to automatically pull my latst commits to dev server

gritty carbon
#

i don't even need to make it acutomatically ๐Ÿ˜ƒ

strange thorn
#

If you've got questions around automating parts of your workflow #414737889352744971 is always a good place to ask

gritty carbon
#

ok , thank you ๐Ÿ˜ƒ

meager anchor
#

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

keen ore
#
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

meager anchor
#

i would add some authorization to that

keen ore
#
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

meager anchor
#

๐Ÿ‘

keen ore
#

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

meager anchor
#

good stuff ๐Ÿ‘

#

i've actually been wondering what the best way to autodeploy successfull branches might be

keen ore
#

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

meager anchor
#

you don't need to restart gunicorn, you can tell it to reload and it will gracefully stop and start new workers, IIRC

keen ore
#

hmm, i have it set as a service

meager anchor
#

I'm not fully sure myself and it's something i'm also currently trying to figure out

copper forge
#

Can someone tell me what this site is using for the UI, its so cool : http://www.zelaacoin.com

buoyant ledge
#

Looks like it was made by softnio

copper forge
#

Hmm

potent nebula
#

someone help me?

#

I have a little problem with the flask

#

but, google and starckoverflow no help me.

rigid turtle
#

What's the problem?

potent nebula
#

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

rigid turtle
#

Windows service?

potent nebula
#

list

#

ready*

#

i set pathexe with binary (exe)

rigid turtle
#

Where is flask getting started?

#

Is that the "serviceweb.exe"?

potent nebula
#

yes

#

i compile the script

rigid turtle
#

So it works on it's own when you run it, but it doesn't work when the service starts it?

potent nebula
#

I can not install anything, more than a service as executable, I'm limited

rigid turtle
#

ok

potent nebula
#

"So it works on it's own when you run it, but it doesn't work when the service starts it?(edited) "

#

exactly

rigid turtle
#

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)

potent nebula
#

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?

rigid turtle
#

maybe

potent nebula
#

umm

#

thanks for everything

granite wigeon
#

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

potent nebula
#

yp

#

yp

#

yep

granite wigeon
#

the api returns that if someone visits from a browser?

potent nebula
#

will the visit be from the browser?

granite wigeon
#

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

potent nebula
#

one second

rigid turtle
#

Sorry I couldn't be more helpful, not experienced with Flask

potent nebula
#

use a condition for when it is a browser

#

agnt

granite wigeon
#

alright ill look into it thanks

#

@potent nebula for your pyinstaller question are you sure the service is finding and starting the .exe correctly?

queen needle
#

@potent nebula @granite wigeon isn't it better to return a response with Flask's redirect function rather than a raw meta tag?

native tide
#

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?

granite wigeon
#

@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

queen needle
#

url_for?

granite wigeon
#
def redirectapi():
    return redirect(url_for('views.index'))```
@queen needle
queen needle
#

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?

granite wigeon
#

returns json info if i have the api unprotected

queen needle
#

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

granite wigeon
#

yea its an api endpoint

#

so i should return a 302 via the api when the content type is text/html?

queen needle
#

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

granite wigeon
#

ill give that a try real quick

queen needle
#

However: redirects in REST api do no make much sense usually

granite wigeon
#

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

queen needle
#

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

granite wigeon
#

yea i couldnt find much for it either

queen needle
#

I think you should just ignore it

#

There is nothing preventing a user from doing a GET on a rest api

granite wigeon
#

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

queen needle
#

Normally if you have some kind of authorisation for that api, you won't have to worry

granite wigeon
#

yea i will set up one with jwt tokens

queen needle
#

@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

granite wigeon
#

yea i agree it was just a minor thing that i got distracted with last night

keen ore
#

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>
queen needle
#

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

keen ore
#

hmm

queen needle
#

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

keen ore
#

those are checkboxes

#

well the checkbox is invisible as the label is used to make the look

queen needle
#

I see, a button-group?

keen ore
#

?

queen needle
#

Are you using bootstrap?

keen ore
#

yes

queen needle
#

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...

keen ore
#

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

queen needle
#

You could write a jinja2 macro that does it for you