|
huhu posted:I tried to add I'm assuming that you are using Flask-Login here, but the gist of my advice should apply to you. Somewhere in the code, Flask-Login is using this code to redirect your user to your login page: Python code:
- Look for the Blueprint named auth and; - Build a url for the login endpoint in the blueprint. You are using @app.route, which means that your login endpoint is directly under the application object. There's nothing wrong with this per se, but blueprints are mostly used to organize code, which is a good thing. The biggest drawback is that, compared to the normal Flask way of creating routes, they have a bit of architectural overhead. That said, you have two options here: 1) Create an auth blueprint and put your login route in there; 2) Change Flask-Login's login route in the login manager.
|
# ¿ Mar 9, 2017 14:37 |
|
|
# ¿ Apr 29, 2024 11:06 |
|
Why don't you just use a localization library like Babel?
|
# ¿ Mar 10, 2017 14:00 |
|
Flask admin views have the is_accessible and inacessible_callback methods to control who it lets access and how it should behave when an unauthorized user tries to access their pages. For example: Python code:
|
# ¿ Mar 10, 2017 20:14 |
|
If you add items like you did in your example, you should be fine. The problem is when you do it like this: Python code:
|
# ¿ Mar 14, 2017 21:18 |
|
It's right there on the quote that you should not rely on that ordering.
|
# ¿ Mar 15, 2017 00:18 |
|
I try to start with None or a boolean value if I don't have a default value that makes sense.
|
# ¿ Mar 15, 2017 13:23 |
|
Sorry to be unspecific, but in that case you have to analyze whatever makes the most sense to you and work around the code's limitations.
|
# ¿ Mar 15, 2017 13:34 |
|
huhu posted:I've got a login form and a registration form on a single page with a nav that toggles a hidden class between the two. By default, when the page loads, registration is set to hidden. However, if a user fills out the registration form and there are errors on submit, the page refreshes and login is loaded. How could I get the hidden class to instead be applied to registration if a user registers but has errors? Pass a flag to the template and, depending on the state of the flag, apply (or not) the class to the offending elements. Python code:
HTML code:
Space Kablooey fucked around with this message at 04:43 on Mar 17, 2017 |
# ¿ Mar 17, 2017 04:39 |
|
It's throwing a syntax error because it's missing the except clause. By the way, you can rewrite any file opening operation as: Python code:
|
# ¿ Mar 23, 2017 21:45 |
|
Lysidas posted:except clauses are not required if there's a finally. Neat. I didn't know about that. Space Kablooey fucked around with this message at 13:45 on Mar 24, 2017 |
# ¿ Mar 24, 2017 13:40 |
|
nvm
Space Kablooey fucked around with this message at 15:32 on Mar 30, 2017 |
# ¿ Mar 30, 2017 15:23 |
|
funny Star Wars parody posted:Ok here's a dumb question: I want to make a unicornhat (which uses a Python library) on a raspberry pi do something when a new order is placed, and according to the Shopify API, you would use their webhook to do it and you supply them with the URL for the webhook to deliver a HTTP POST payload to in json format. Yes, that is correct. Your URL should point to a live server that is expecting a POST with the format that Shopify sends you. I don't know any specifics of Raspberry, so I can't really help you with your second question.
|
# ¿ Mar 31, 2017 14:16 |
|
funny Star Wars parody posted:I use Python 2.7 anyways so yayyy The pricing depends on Amazon Lambda's pricing, but you will probably be well within the free tier.
|
# ¿ Apr 1, 2017 01:03 |
|
Dominoes posted:Re Flask vs Django: Django for websites, Flask for other things you need a webserver for. Flask becomes a pain once you start adding plugins for things like admin, auth, migrations, databases etc. Outside of a very specific library (Flask-Social), I had no issues with any Flask extension so far. I'll give you that it's easier than Django to make a mess of packages and modules and dependencies when your project grows. Space Kablooey fucked around with this message at 03:25 on Apr 1, 2017 |
# ¿ Apr 1, 2017 03:20 |
|
The error is pretty straightforward, item['link'] is a list of somethings (or it could be empty). You can try printing it out and seeing if whatever you want is in there, and then you can concatenate with your follow link.
|
# ¿ Apr 4, 2017 02:54 |
|
I'd indent the other conditions and invert the any to get rid of the pass, otherwise it looks fine to me.
|
# ¿ Apr 7, 2017 21:06 |
|
Can someone explain to me what's going on here:Python code:
Edit: nvm, it's pretty obvious. Space Kablooey fucked around with this message at 18:31 on Apr 10, 2017 |
# ¿ Apr 10, 2017 18:25 |
|
QuarkJets posted:sorry i meant i thought you knew that _ is also completely uninformative. i think you meant [unused for unused in range(0,1,1)]
|
# ¿ Apr 12, 2017 14:06 |
|
Cingulate posted:For real though, how did you oldsters ever live with Python 2 and its leaking list comps? You mean the leaking variable that is used on building the comps or you mean like a memory leak or something like that? How to live with the former is to just redefine the name before reusing.
|
# ¿ Apr 12, 2017 14:24 |
|
I'm not sure if I dislike comprehensions leaking, tbh.Python code:
Space Kablooey fucked around with this message at 14:16 on Apr 13, 2017 |
# ¿ Apr 13, 2017 14:13 |
|
I still think subclassing is the better option, if anything because it is the simplest way.
|
# ¿ Apr 20, 2017 13:43 |
|
Symbolic Butt posted:Most likely yes. If you make it explicit that the number part is an integer you'll get the sorting you want: I didn't know you could compare tuples like that.
|
# ¿ Apr 24, 2017 19:13 |
|
Eela6 posted:pathlib Paths are hashable and orderable (and therefore sortable) so you can just call sorted! How does it deal with a folder that has file1, file9, file10 and so on?
|
# ¿ Apr 24, 2017 19:55 |
|
Just had a quick glance at it, but you could Space Kablooey fucked around with this message at 21:21 on Apr 24, 2017 |
# ¿ Apr 24, 2017 21:17 |
|
huhu posted:I've just finished my first Flask project for my new job which is basically a page with a form that allows users to do CRUD operations on a database table. It took me about a week to create. Of course there was a bunch of stuff like having to learn MySQL, JavaScript form validation, navigate their code base, etc. along the way so it took a bit of time. I was just able to recreate what took me about a week with Flask Admin in an hour and was even able to add additionally functionality like a list view, searching, and filtering. I feel like this was deceptively simple though and when I start working on more complex projects I'd be better off writing the SQL and JS myself. Is that correct? At some point yes, you will have to customize something or other, but Flask Admin really is that powerful.
|
# ¿ Apr 27, 2017 01:28 |
|
The liquor store?
|
# ¿ May 3, 2017 16:53 |
|
I think it depends on the protocols, IIRC. If you are using HTTP/S you have to make one request per connection, but if you are using TCP or UDP you could make something like that, but I wouldn't know how with requests, but it shouldn't be too hard.
|
# ¿ Jun 2, 2017 19:07 |
|
I think your case right now is a really good starting point for learning about classes! Unfortunately I don't have a suitable beginner guide on those on hand right now, but you could just google "classes in python" or something like that and start from there. Also: Mirthless posted:tbh the constant nagging feeling that i'm doing it wrong makes programming really discouraging Whenever you get that "There has to be a better way of doing this" feeling, you should reach out and ask. Especially if you just starting out programming. Space Kablooey fucked around with this message at 15:38 on Jul 5, 2017 |
# ¿ Jul 5, 2017 15:36 |
|
Yeah, that's a job for a rq or celery setup.
|
# ¿ Dec 1, 2017 19:50 |
|
If you still want to use virtuaenv, you should take a look into at virtualenvwrapper which is a set of convenience scripts over virtualenv (meaning source virtualenv/bin/activate becomes workon <name_of_env> and so on). I think the new hotness is pipenv, though, but I never used it.
|
# ¿ Jan 3, 2018 14:17 |
|
So a friend of mine is about to start a Python programming job, and he asked me if I had any Python beginner resources. I recommended Fluent Python and Think Python, but I'm not sure if there's more than that that's highly recommended. Fake edit: Nevermind, I found this huge list in the Python website: https://wiki.python.org/moin/BeginnersGuide/Programmers Space Kablooey fucked around with this message at 03:22 on Jan 26, 2018 |
# ¿ Jan 26, 2018 03:19 |
|
I mean you could (and should) make that into a function, but you can get the token by doing requests.json()['data'][0]['token'] directly. To expand, request.json() returns a python dictionary (and not a string), that is, in short, a data structure that maps keys into values. So, for that particular dictionary, your token is inside a dictionary, under the key "token", that is inside a single element list (so index 0), that is inside another dictionary, under the key "data".
|
# ¿ Apr 2, 2018 02:09 |
|
Sqlalchemy .one() returns exactly one result or returns an error .one is a bit of a minefield on SQLAlchemy to say the least. IME it's more intended to be the execution of a string of filters, and then to validate if there's exactly one of a record with that criteria, and, lastly to return it. It will raise errors if there's no record matching that criteria or if there's more than one record matching that criteria. If you just want one object and don't care which record it is, you should use .first instead. Be aware that this will be the first record found by the database, which may or may not be ordered according to the primary key(s).
|
# ¿ Apr 11, 2018 19:05 |
|
No problems! I've worked with SQLA for a long time and I still make that mistake when I'm writing one-off scripts far more often than I'd like. I have no clue why it takes hours for you, though. Hopefully .first will be much, much faster.
|
# ¿ Apr 11, 2018 19:49 |
|
Python code:
Python code:
|
# ¿ Apr 13, 2018 18:12 |
|
Which testing framework is the new hotness nowadays? I've been using nose for the longest time and I want to get on with the times.
|
# ¿ Apr 18, 2018 19:07 |
|
Hypothesis looks pretty cool, thanks.
|
# ¿ Apr 19, 2018 16:33 |
|
I never used webbrowser before, but reading the docs, you should either: 1) Use webbrowser.open and just pass the URL, and the system will open the given URL in the default browser, or 2) If you actually need a reference to the browser controller, you just need to pass the name of the browser to webbrowser.get, and then use one of the open methods listed.
|
# ¿ May 6, 2018 14:43 |
|
|
# ¿ Apr 29, 2024 11:06 |
|
{item['Key']: item['Value'] for item in n['Tags']}
|
# ¿ May 7, 2018 18:55 |