Most Popular
1500 questions
1350
votes
28 answers
What is the difference between null=True and blank=True in Django?
When we add a model field in Django we generally write:
models.CharField(max_length=100, null=True, blank=True)
The same is done with ForeignKey, DecimalField etc. What is the basic difference between:
null=True only
blank=True only
null=True and…
user993563
- 18,601
- 10
- 42
- 55
1348
votes
15 answers
How do I check if a variable exists?
I want to check if a variable exists. Now I'm doing something like this:
try:
myVar
except NameError:
# Do something.
Are there other ways without exceptions?
Max Frai
- 61,946
- 78
- 197
- 306
1348
votes
17 answers
Correct way to write line to file?
How do I write a line to a file in modern Python? I heard that this is deprecated:
print >>f, "hi there"
Also, does "\n" work on all platforms, or should I use "\r\n" on Windows?
Yaroslav Bulatov
- 57,332
- 22
- 139
- 197
1347
votes
35 answers
Access-Control-Allow-Origin Multiple Origin Domains?
Is there a way to allow multiple cross-domains using the Access-Control-Allow-Origin header?
I'm aware of the *, but it is too open. I really want to allow just a couple domains.
As an example, something like this:
Access-Control-Allow-Origin:…
Thomas J Bradley
- 13,726
- 3
- 18
- 8
1345
votes
22 answers
Why do people write "#!/usr/bin/env python" on the first line of a Python script?
I see these at the top of Python files:
#!/usr/bin/env python
#!/usr/bin/env python3
It seems to me that the files run the same without that line.
john garcias
- 13,555
- 3
- 16
- 3
1345
votes
14 answers
SOAP vs REST (differences)
I have read articles about the differences between SOAP and REST as a web service communication protocol, but I think that the biggest advantages for REST over SOAP are:
REST is more dynamic, no need to create and update UDDI(Universal…
Abdulaziz
- 13,694
- 3
- 13
- 12
1344
votes
18 answers
How do I set/unset a cookie with jQuery?
How do I set and unset a cookie using jQuery, for example create a cookie named test and set the value to 1?
omg
- 136,412
- 142
- 288
- 348
1343
votes
13 answers
How to reload a page using JavaScript
How can I reload the page using JavaScript?
I need a method that works in all browsers.
Resh
- 13,439
- 3
- 15
- 3
1343
votes
13 answers
git: undo all working dir changes including new files
How to delete all changes from working directory including new untracked files. I know that git checkout -f does that, but it doesn't delete new untracked files created since last commit.
Does anybody have an idea how to do that?
Aler
- 15,097
- 6
- 23
- 26
1342
votes
42 answers
What's the difference between a mock & stub?
I've read various articles about mocking vs stubbing in testing, including Martin Fowler's Mocks Aren't Stubs, but still don't understand the difference.
never_had_a_name
- 90,630
- 105
- 267
- 383
1342
votes
13 answers
UTF-8 all the way through
I'm setting up a new server and want to support UTF-8 fully in my web application. I have tried this in the past on existing servers and always seem to end up having to fall back to ISO-8859-1.
Where exactly do I need to set the encoding/charsets?…
mercutio
- 22,151
- 10
- 36
- 37
1342
votes
26 answers
How should I ethically approach user password storage for later plaintext retrieval?
As I continue to build more and more websites and web applications I am often asked to store user's passwords in a way that they can be retrieved if/when the user has an issue (either to email a forgotten password link, walk them through over the…
Shane
- 16,779
- 5
- 27
- 46
1342
votes
33 answers
Difference between "wait()" vs "sleep()" in Java
What is the difference between a wait() and sleep() in Threads?
Is my understanding that a wait()-ing Thread is still in running mode and uses CPU cycles but a sleep()-ing does not consume any CPU cycles correct?
Why do we have both wait() and…
Geek
- 23,089
- 20
- 71
- 85
1340
votes
17 answers
Replace one substring for another string in shell script
I have "I love Suzi and Marry" and I want to change "Suzi" to "Sara".
firstString="I love Suzi and Marry"
secondString="Sara"
Desired result:
firstString="I love Sara and Marry"
Zincode
- 13,441
- 3
- 13
- 6
1339
votes
27 answers
How do I collapse sections of code in Visual Studio Code for Windows?
How do I fold or collapse sections of code in Visual Studio Code?
Is this feature supported?
Nick
- 14,291
- 3
- 17
- 19