Due to school asignment, I have to write a wedsite with flask appbuilder, when I try to add a register page, I don't need the RECAPTCHA.
So, how can I disable this?
I tried:
add RECAPTCHA_ENABLED = False in config.py --- [not working, the RECAPTCHA fleid still there]
Related
I recently started learning flask and created a simple webapp which randomly generates kids' math work sheets in PDF based on user input.
The PDF opens automatically in a browser and can be viewed. But when I try downloading it both on a PC and in Chrome iOS, I get error messages (Chrome PC: Failed - Network error / Chrome iOS:the file could not be downloaded at this time).
You can try it out here: kidsmathsheets.com
I suspect it has something to do with the way I'm generating and returning the PDF file. FYI I'm using ReportLab to generate the PDF. My code below (hosted on pythonanywhere):
from reportlab.lib.pagesizes import A4, letter
from reportlab.pdfgen import canvas
from reportlab.platypus import Table
from flask import Flask, render_template, request, Response
import io
from werkzeug import FileWrapper
# Other code to take in input and generate data
filename=io.BytesIO()
if letter_size:
c = canvas.Canvas(filename, pagesize=letter)
else:
c = canvas.Canvas(filename, pagesize=A4)
pdf_all(c, p_set, answer=answers, letter=letter_size)
c.save()
filename.seek(0)
wrapped_file = FileWrapper(filename)
return Response(wrapped_file, mimetype="application/pdf", direct_passthrough=True)
else:
return render_template('index.html')
Any idea what's causing the issue? Help is much appreciated!
Please check whether you are using an ajax POST request for invoking the endpoint to generate your data and display the PDF respectively. If this is the case - quite probably this causes the behaviour our observe. You might want to try invoking the endpoint with a GET request to /my-endpoint/some-hashed-non-reusable-id-of-my-document where some-hashed-non-reusable-id-of-my-documentwill tell the endpoint which document to serve without allowing users to play around with guesstimates about what other documents you might have. You might try it first like:
#app.route('/display-document/<document_id>'):
def display_document(document_id):
document = get_my_document_from_wherever_it_is(document_id)
binary = get_binary_data_from_document(document)
.........
Prepare response here
.......
return send_file(binary, mimetype="application/pdf")
Kind note: a right click and 'print to pdf' will work but this is not the solution we want
I'm trying to fetch data for facebook account using selenium browser python but can't able to find the which element I can look out for clicking on an export button.
See attached screenshot
I tried but it seems giving me an error for the class.
def login_facebook(self, username, password):
chrome_options = webdriver.ChromeOptions()
preference = {"download.default_directory": self.section_value[24]}
chrome_options.add_experimental_option("prefs", preference)
self.driver = webdriver.Chrome(self.section_value[20], chrome_options=chrome_options)
self.driver.get(self.section_value[25])
username_field = self.driver.find_element_by_id("email")
password_field = self.driver.find_element_by_id("pass")
username_field.send_keys(username)
self.driver.implicitly_wait(10)
password_field.send_keys(password)
self.driver.implicitly_wait(10)
self.driver.find_element_by_id("loginbutton").click()
self.driver.implicitly_wait(10)
self.driver.get("https://business.facebook.com/select/?next=https%3A%2F%2Fbusiness.facebook.com%2F")
self.driver.get("https://business.facebook.com/home/accounts?business_id=698597566882728")
self.driver.get("https://business.facebook.com/adsmanager/reporting/view?act="
"717590098609803&business_id=698597566882728&selected_report_id=23843123660810666")
# self.driver.get("https://business.facebook.com/adsmanager/manage/campaigns?act=717590098609803&business_id"
# "=698597566882728&tool=MANAGE_ADS&date={}-{}_{}%2Clast_month".format(self.last_month,
# self.first_day_month,
# self.last_day_month))
self.driver.find_element_by_id("export_button").click()
self.driver.implicitly_wait(10)
self.driver.find_element_by_class_name("_43rl").click()
self.driver.implicitly_wait(10)
Can you please let me know how can i click on Export button?
Well, I'm able to resolve it by using xpath.
Here is the solution
self.driver.find_element_by_xpath("//*[contains(#class, '_271k _271m _1qjd layerConfirm')]").click()
The element with text as Export is a dynamically generated element so to locate the element you have to induce WebDriverWait for the element to be clickable and you can use either of the locator strategies:
Using CSS_SELECTOR:
WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.layerConfirm>div[data-hover='tooltip'][data-tooltip-display='overflow']"))).click()
Using XPATH:
WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(#class, 'layerConfirm')]/div[#data-hover='tooltip' and text()='Export']"))).click()
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
to run automation scripts on applications like facebook, youtube quite a hard because they are huge coporations and their web applications are developed by the worlds best developers but its not impossible to run automation scripts sometimes elements are generated dynamically sometimes hidden or inactive you cant just go and click
one solution is you can do by click action by xpath realtive or absolute their is not id specified as "export_button" in resource file i think this might help you
you can also find element by class name or css selector as i see in screen shot the class name is present "_271K _271m _1qjd layerConfirm " you can perform click action on that
I am working with a Delayed Job that, after its completion, sends an email to the admin user that requested it. So, to do this, I need to know who is the admin user that launched it inside the Spree::Order model.
I've tried with try_spree_current_user and spree_current_user but they don't work returning:
NameError (undefined local variable or method `try_spree_current_user' for #<Spree::Order:0x007f93811d7240>):
app/models/spree/order_decorator.rb:30:in `after_cancel'
app/controllers/spree/admin/orders_controller_decorator.rb:4:in `cancel'
Some how you need to make sure that an admin can launch the order:
# Is this user an admin
if spree_current_user.admin?
# Do some delayed job
# send the email
# because spree_current_user.id is the one that sends it
else
flash[:error] = "You need to be an admin to do this."
redirect_back_or_default(spree.root_path)
end
The above should do what you want to do. You need to test if the current user is an admin then do what he/she needs to do.
I'm sure you meant the OrdersController? Not model.
I installed ROR and SPREE in windows. When I am running the site, logo not displaying in the demo content.
Please tell the solution to fix it. I tried to change the logo using spree.rb with below code:
# Example:
# Uncomment to stop tracking inventory levels in the application
# config.track_inventory_levels = false
Try to use something like this. may be it is helpful to you:
Spree.config do |config|
config.admin_interface_logo = 'logo/some_other_logo.png'
config.logo = 'logo/this_logo.png'
end
Right away: yes I know about INTERNAL_IPS.
I'm about to have my django app opened up at work integration and testing. I know there will be debugging and plenty modifications and/or optimizations to be made so I'd love to have the Django Debug Toolbar. However, I'd prefer to not have it up for all of my co-workers (who are the 'clients').
The reason the INTERNAL_IP setting doens't work for just me (btw: I have a static IP on my development computer) is that I am using Nginx as a reverse-proxy and serving with Gunicorn. Because of the reverse-proxy, using an internal_ip of 127.0.0.1 shows DjDT to any computer on the network and using that ip is the only way I've been able to see it myself.
What I'm looking for is either a way to get my IP or my login name to be the only one to access the toolbar. I once saw a thread about the user name limited access but I can't find it...
And as a side question- anyone know why the toolbar doesn't render in IE? For me it just shows as tables on the bottom of the page.
Try:
def show_toolbar(request):
return not request.is_ajax() and request.user and request.user.username == "yourusername"
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': 'projectname.settings.show_toolbar',
# Rest of config
}
The accepted answer is no longer correct. Newer versions of the toolbar need the value of the SHOW_TOOLBAR_CALLBACK key to be a string with the full import path of the function. So if you're defining your callback function your settings.py file, you'd have to add:
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': 'projectname.settings.show_toolbar',
}
If you face No .rsplit() Error. NEW SOLUTION:
Because SHOW_TOOLBAR_CALLBACK is now a dotted string path and not support a callable.
edit your settings.py:
def custom_show_toolbar(request):
return True # Always show toolbar, for example purposes only.
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': 'your_project_name.settings.custom_show_toolbar',
}
In Django 4+ this username validation worked for me:
def show_toolbar(request):
return str(request.user) == "username" #... any other validations