How to use variables in django url path? [closed] - arrays

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 2 years ago.
Improve this question
I am developing and Django website, and I have an array of some str values(parts of url).When user is redirect to:
https://www.example.com/something/name/
how can system system knows that that is part of that arry.
I alredy have this:
urlpatterns = [
path(r'<name1>, views.example')
]
And Array:
arr = [name1,name2,name3, ....namen] # elements of array are assigned to variables in for loop.
Thank you in advance.

So you need to change urlpatterns to:
path('<str:name>,views.example)
str is data type, and other data type for this use are:
int – Matches zero or any positive integer.
str – Matches any non-empty string, excluding the path separator(‘/’).
slug – Matches any slug string, i.e. a string consisting of alphabets, digits, hyphen and under score.
uuid – Matches a UUID(universal unique identifier).
And function call to:
views.example(request, name = "name_n") # for better code reading use name_1, name_2, .. name_n instead of name1,name2 etc.
and that would be it, enjoy in Django.

Related

request for member 'nama' in something not a structure or union [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 4 years ago.
Improve this question
so i have this code, but when im running it, it's shows that "error : request for member 'nama' in something not a structure or union.
this is an admin program when you buy a movie ticket, and the modul need the name of the admin to print it in the ticket
struct admin
{
char nama[100];
char id[100];
char password[100];
};
struct admin pengatur[100];
ModeAdmin(pengatur[counter]);
void ModeAdmin(struct admin *c)
{
struct admin pembuka;
strcpy(pembuka.nama,c.nama);
strcpy(pembuka.id,c.id);
strcpy(pembuka.password,c.password);
printf("Welcome %s",pembuka.nama);
printf("1. Print Ticket\n");
printf("2. Add New Film\n");
}
This:
c.nama
should be:
c->nama
since c is not a struct or union, it's a pointer to a struct.
c is a pointer to a struct, not a struct itself, so you can't use the . operator on it. You need to instead use ->, which dereferences the pointer and then gets the member:
strcpy(pembuka.nama,c->nama);
strcpy(pembuka.id,c->id);
strcpy(pembuka.password,c->password);
Change
strcpy(pembuka.nama,c.nama);
to
strcpy(pembuka.nama,c->nama);
And all other occurences of c. likewise.
It is necessary because while pembuka is of type struct admin, c is only a pointer to one.

Covert array date string and decrease 3 hours in Shell Script [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 6 years ago.
Improve this question
I need from an array decrease 3 hours from it and print in command line again
the output of the array is:
12:29:14
14:10:26
14:30:34
14:35:31
14:35:10
11:57:03
12:49:31
12:57:09
11:04:49
13:06:57
14:35:34
14:30:49
14:34:28
12:58:02
14:28:12
12:29:18
11:33:23
12:27:04
14:35:43
12:58:46
I am trying with this line, but no use.
date2=$(date -d "${array[#]}" "3 hour ago" +"%H:%M:%S")
Could you please help me about it?
try this;
#!/bin/bash
times=( "12:29:14" "14:10:26" "14:30:34" "14:35:31" "14:35:10" "11:57:03" "12:49:31" "12:57:09" "11:04:49" "13:06:57" "14:35:34" "14:30:49" "14:34:28" "12:58:02" "14:28:12" "12:29:18" "11:33:23" "12:27:04" "14:35:43" "12:58:46")
for dateItem in ${times[#]}
do
date2=$(date --date="$dateItem 3 hour ago" +%H:%M:%S)
echo $date2
done
Hi It's worked after doing some changes it works correct,
If you wish todo it without an array
Here it is:
date2=$(date -d "$times 3 hour ago" +"%H:%M:%S")
echo $date2

How to get the Query values? [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
SqlDatasource1 :
Table1
-----------
Result_1
-----------
Result_2
I have a query, and I want to get a Result_2 value from the query in code behind, in the BeforePrint event, and I don´t want to put a label in the report, how can I do this?
Thanks
If you want to manually run the Select command on your data source, you could try something like (C#):
var dv = new DataView()
dv = Sqldatasource1.Select(DataSourceSelectArguements.Empty) as DataView;
if (dv.Count > 0)
{
foreach (DataRowView rv in dv)
{
string Result2Val = rv["Result_2"].ToString();
// do something with the result...
}
}
I'm sure VB will follow a similar pattern.
Alternatively, try and capture the OnSelected event, if it's already being triggered by another control.

Can I use while(strstr(name[a],sname)!=NULL) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm writing a phonebook application and one of the functions is for searching the phonebook by name.
The program should print out the names the same way as the user entered them (later I will include the numbers and other info). The phonebook has 100 contacts.
sname is the name that user have entered to search.
name[a] is name list. Is there any other code like strstr? Like its operating if its found printing them if not then print("not found any") something like this:
for(a=1; a<101; a++) {
while(strstr(name[a],sname) != NULL) {
printf(strstr(name[a], sname));
}
}
You can do that: it is an infinite loop.
while(strstr(name[a],sname)!=NULL){
printf("%s\n",strstr(name[a],sname));
}
None of a, name[a], sname change in the conditions or body of the while

Stop word removal in Javascript [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
HI I am looking for a library that'll remove stop words from text in Javascript, my end goal is to calculate tf-idf and then convert the given document into vector space, and all of this is Javascript.
Can anyone point me to a library that'll help me do that.Just a library to remove the stop words would also be great.
Use the stopwords provided by the NLTK library:
stopwords = ['i','me','my','myself','we','our','ours','ourselves','you','your','yours','yourself','yourselves','he','him','his','himself','she','her','hers','herself','it','its','itself','they','them','their','theirs','themselves','what','which','who','whom','this','that','these','those','am','is','are','was','were','be','been','being','have','has','had','having','do','does','did','doing','a','an','the','and','but','if','or','because','as','until','while','of','at','by','for','with','about','against','between','into','through','during','before','after','above','below','to','from','up','down','in','out','on','off','over','under','again','further','then','once','here','there','when','where','why','how','all','any','both','each','few','more','most','other','some','such','no','nor','not','only','own','same','so','than','too','very','s','t','can','will','just','don','should','now']
Then simply pass your string into the following function:
function remove_stopwords(str) {
res = []
words = str.split(' ')
for(i=0;i<words.length;i++) {
word_clean = words[i].split(".").join("")
if(!stopwords.includes(word_clean)) {
res.push(word_clean)
}
}
return(res.join(' '))
}
Example:
remove_stopwords("I will go to the place where there are things for me.")
Result:
I go place things
Just add any words to your NLTK array that aren't covered already.
I think there are no libraries for such thing, you need to download those words from https://www.ranks.nl/stopwords.
And then do replace the words as follows:
text = text.replace(stopword, "")
Here's an array with english stopwords. Hope it helps. From http://www.ranks.nl/stopwords (mentioned in previous answer).
Also, this could be a helpful resource for you.
https://github.com/shiffman/A2Z-F16/tree/gh-pages/week5-analysis
http://shiffman.net/a2z/text-analysis/
var stopwords = ["a", "about", "above", "after", "again", "against", "all", "am", "an", "and", "any","are","aren't","as","at","be","because","been","before","being","below","between","both","but","by","can't","cannot","could","couldn't","did","didn't","do","does","doesn't","doing","don't","down","during","each","few","for","from","further","had","hadn't","has","hasn't","have","haven't","having","he","he'd","he'll","he's","her","here","here's","hers","herself","him","himself","his","how","how's","i","i'd","i'll","i'm","i've","if","in","into","is","isn't","it","it's","its","itself","let's","me","more","most","mustn't","my","myself","no","nor","not","of","off","on","once","only","or","other","ought","our","ours","ourselves","out","over","own","same","shan't","she","she'd","she'll","she's","should","shouldn't","so","some","such","than","that","that's","the","their","theirs","them","themselves","then","there","there's","these","they","they'd","they'll","they're","they've","this","those","through","to","too","under","until","up","very","was","wasn't","we","we'd","we'll","we're","we've","were","weren't","what","what's","when","when's","where","where's","which","while","who","who's","whom","why","why's","with","won't","would","wouldn't","you","you'd","you'll","you're","you've","your","yours","yourself","yourselves"];
There's a Javascript Library for removing stopwords here: http://geeklad.com/remove-stop-words-in-javascript

Resources