[Solved] Please I’m new to python and I’m trying to do a recipe app using Django. I encountered an error which is “UnboundLocalError: local variable form [closed]

you only create form if your request is POST. so if you try to call your view with get method form variable is not created. this is your code I’m gonna walk you through it. def register(request): if request.method == “POST”: form = UserCreationForm(request.POST) if form.is_valid(): username = form.cleaned_data.get(‘username’) messages.success(request,f”{username}, your account has been created!”) … Read more

[Solved] How to prompt error on TextInput [closed]

This is with Text Input Layout in xml Layout file <android.support.design.widget.TextInputLayout android:id=”@+id/input_layout_password” android:layout_width=”match_parent” android:layout_height=”wrap_content”> <EditText android:id=”@+id/textView_password” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:hint=”@string/password” android:inputType=”textPassword” /> </android.support.design.widget.TextInputLayout> Your activity should be something like this. passwordTIL = (TextInputLayout) findViewById(R.id.input_layout_password); passwordET = (EditText) findViewById(R.id.textVIew_password); passwordET.addTextChangedListener(new SigninTextWatcher(passwordET) //you can use this for username too or to check if the email format is correct … Read more

[Solved] Is Java HashSet add method thread-safe?

No, HashSet is not thread-safe. You can use your own synchronization around it to use it in a thread-safe way: boolean wasAdded; synchronized(hset) { wasAdded = hset.add(thingToAdd); } If you really need lock-free performance, then you can use the keys of a ConcurrentHashMap as a set: boolean wasAdded = chmap.putIfAbsent(thingToAdd,whatever) == null; Keep in mind, … Read more

[Solved] Does this class violate SOLID’s single responsibility principle? [closed]

As your class above has atleast two responsibilities i.e. creating a database connection and performing CRUD operations on the entities, so I think it violates the SOLID’s single responsibility principle. You might create a seperate class to deal with the Database connection and register it as a dependency (through an interface) to the Database class … Read more

[Solved] How to add regular expression to jenkins pipeline? [closed]

Please read documents carefully before asking! There is no syntax format like “when + environment”. Try “when + expression”, for example: stage(“example”) { when { expression { return egText.contains(“abcd”) } } Beside that, about environment: The environment directive specifies a sequence of key-value pairs which will be defined as environment variables for all steps, or … Read more

[Solved] Smart assuming of variable type

You can use https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates But you need to pass the variable const isLoaded = (response: ResponseData | undefined): response is ResponseData => { // some complex logic to check if the data is loaded and correct return !isLoading && !!data && Object.keys(data).length > 0 } return ( <> <div>My data title:</div> {isLoaded(data) && <div>{data.title}</div>} // … Read more

[Solved] GridView is not refreshing with notifyDataSetChanged()

First thing first notifyDataSetChanged() only will work with the same reference of dataset . And you have created a new list int your adapter’s constructor . So you are going nowhere from here . It should as simple as . private ArrayList mArraylist = new ArrayList(); public MenuGridViewAdapter(Activity activity, ArrayList mArraylist) { this.activity = activity; … Read more

[Solved] How to count and update label without saving in database in vb.net? [closed]

You could set a ‘baseDate’ in your code as ‘1/13/2018’ in order to compare it with today’s date. Then you just need to get the days in between, and get its “module 3” value: Dim baseDateString = “14/01/2018” Dim baseDate As Date = Date.ParseExact(baseDateString, “dd/MM/yyyy”, System.Globalization.DateTimeFormatInfo.InvariantInfo) Dim datetimeBetween = DateTime.Today.Subtract(baseDate) Dim daysBetween = datetimeBetween.Days Dim … Read more

[Solved] i want to generate an exception when user enters integer values instead of String value.. how can i do it?

Since you are interested in Type Checking, You may want to reverse your Logic a little bit like so: def log_in(): user_name1 = “xyz” user_name = input(“Enter your username:\n”) # str() try: # FOR YOUR USE CASE, IT WOULD SUFFICE TO SIMPLY TRY TO CAST THE ENTERED # INPUT TO AN INT (INITIALLY) – REGARDLESS … Read more

[Solved] For-loop condition mechanic for Pyramid code

This is all about noticing patterns in a pyramid. The comment for the first for loop says that it is printing the correct number of spaces before the actual pyramid (i.e. the asterisks). Let’s look at how many spaces there are at each level: * level 0 – 4 spaces *** level 1 – 3 … Read more