Flask-Admin - what to pass in url_for(' ')? [closed] - flask

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I got an error, that says, that no URL can be build from that parameter inside url_for('').
I passed url_for('admin') but that does not work. What should I pass to get to localhost:5000/admin ?
Thank you

You pass the name of the definition of the route you want to visit.
For example:
#app.route('/')
def index():
return 'Hello, World!'
...
#app.route('/some_page')
def somewhere_else():
if something_happened:
redirect(url_for('index'))
return render_template('some_page.html')
Or if you are using it inside your HTML:
<a href="{{ url_for('index') }} ...></a>

Related

I need to use RegEx to find a speciffic word in HTML page? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I'm trying to extract a specific word (that might change) which comes after a permanent expression. I want to extract the name Taldor in this code:
<h4 class="t-16 t-black t-normal">
<span class="visually-hidden">Company Name</span>
<span class="pv-entity__secondary-title">Taldor</span>
</h4>
For now I able to find <h4 class="t-16 t-black t-normal"> using this regex:
(?<=<h4 class="t-16 t-black t-normal">).*
Will be glad for any kind of advice.
I'd suggest you to use an HTML parsing library like Jsoup in Java or beautifulsoup in Python to parse HTML instead of using regex for this reason
Following is the kind of code that does the job for you,
String s = "<h4 class=\"t-16 t-black t-normal\">\r\n" +
" <span class=\"visually-hidden\">Company Name</span>\r\n" +
" <span class=\"pv-entity__secondary-title\">Taldor</span>\r\n" +
" </h4>";
Document doc = Jsoup.parse(s);
for (Element element : doc.getElementsByClass("pv-entity__secondary-title")) {
System.out.println(element.text());
break;
}
Prints,
Taldor
In worst case, if you are doing some quick and dirty work, you can do this temporary solution using regex but it is surely not recommended thing to do.
<span class="pv-entity__secondary-title">(.*?)<\/span>
Use this regex and capture your data from group1.
Demo

Bootstrap3 Typeahead - Empty message [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I didn't understand how to make it appear the "empty" message in bootstrap3 typeahead. I am using the custom template but what value must be assigned to source to make it appear?
Here is my code (not working):
<script>
function doSomething() {
var states = [];
$("#test").typeahead({
source : states,
minLength: 3,
templates: {
empty: ['<div>',
'No Items Found',
'</div>'
].join('\n')
}
});
}
</script>
[...]
<body onLoad="doSomething();">
<input class="typeahead" type="text" id="test">
</body>
I confused typeahead (https://github.com/twitter/typeahead.js) with bootstrap3 typeahead (https://github.com/bassjobsen/Bootstrap-3-Typeahead).
The question is wrong because the code above is correct for https://github.com/twitter/typeahead.js, instead I had included https://github.com/bassjobsen/Bootstrap-3-Typeahead, which is a different library and have different options.

Django: How to populate value into form template? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have created a small form which includes something like name, mobile number, age field. All are text fields.
These values are stored in DB.
I want my template to pre-populate the form with values from DB (if exists). How can this be done?
My template code is as below:
<div>
<center><form action="/profilesettings/" method="post" enctype="multipart/form-data">{% csrf_token %}
{{form.as_p}}
<input type="submit" value="submit">
</form></center></div>
Currently, it displays form with empty field. Instead of empty fields, I would like them to show values which are fetched from DB.
check this example on django docs
article = Article.objects.get(pk=1)
article.headline
'My headline'
form = ArticleForm(instance=article)
form['headline'].value()
'Initial headline'

In a Flask app, how to print each item of a list in the new paragraphs inside my HTML page [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm building a Flask app which is supposed to return all the items in a list as a new line in the HTML page.
For example:
list = [1,2,3,4]
I want to print each item in list as a new paragraph in my HTML page, like here:
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
You should better follow the flaskr tutorial on flask web site. It can give you the idea how to pass local variables to the template.
#app.route('/')
def your_view():
your_list= [1,2,3,4]
return render_template('your_view.html', your_list=your_list)
then in your jinja template, iterate over this list.
{% for your_list_element in your_list %}
<p>{{ your_list_element }} </p>
{% endfor %}

ColdFusion - how to edit a record? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want to edit the Record2 but when I click the Edit button it always display the info of Record1. If I click any other Edit buttons it only display the info of Record1. How does it know which record I want to edit? Please help. Thank you.
<cfform name="formName" action="edit.cfm" method="post">
....some additional codes.....
<cfloop query="qryName">
Record1_data Edit button
Record2_data Edit button
Record3_data Edit button
Record4_data Edit button
</cfloop>
....some additional codes.....
</cfform>
Unless there's a really good reason I'd really shy away from using cfform there's rarely a good reason to use it
You need to pass in some sort of form variable that has the corresponding ID to what you're pulling into the database.
<form name="formName" action="edit.cfm" method="post">
<cfloop query="qryName">
<input type="checkbox" name="Record" value="#qryName.ID#" /> Record #qryName.ID#
</cfloop>
</form>