This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form method="post"> | |
{% csrf_token %} | |
{{ form }} | |
<button type="submit">Save changes</button> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<table class="table table-bordered"> | |
<thead> | |
<tr> | |
<th>Title</th> | |
<th>Author</th> | |
<th>Date</th> | |
</tr> | |
</thead> | |
<tbody> | |
{% for article in articles %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.mail import mail_admins | |
def feedback(request): | |
if request.method == 'POST': | |
f = FeedbackForm(request.POST) | |
if f.is_valid(): | |
name = f.cleaned_data['name'] | |
sender = f.cleaned_data['email'] | |
subject = "You have a new Feedback from {}:{}".format(name, sender) | |
message = "Subject: {}\n\nMessage: {}".format(f.cleaned_data['subject'], f.cleaned_data['message']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ------------------------------------- | |
GLOBAL | |
A very basic CSS reset | |
------------------------------------- */ | |
* { | |
margin: 0; | |
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | |
box-sizing: border-box; | |
font-size: 14px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import uuid | |
import hashlib | |
def hash_password(password): | |
# uuid is used to generate a random number | |
salt = uuid.uuid4().hex | |
return hashlib.sha256(salt.encode() + password.encode()).hexdigest() + ':' + salt | |
def check_password(hashed_password, user_password): | |
password, salt = hashed_password.split(':') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-uwsgi-and-nginx-on-ubuntu-16-04 | |
# configuration of the server | |
server { | |
# the port your site will be served on | |
listen 80; | |
listen [::]:80; | |
# the domain name it will serve for | |
server_name 192.168.2.212; | |
charset utf-8; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pipeline | |
# PIPELINE_ENABLED = True | |
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage' | |
STATICFILES_FINDERS = ( | |
'django.contrib.staticfiles.finders.FileSystemFinder', | |
'django.contrib.staticfiles.finders.AppDirectoriesFinder', | |
'pipeline.finders.CachedFileFinder', | |
'pipeline.finders.PipelineFinder', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FeedbackFormView(FormView): | |
form_class = FeedbackForm | |
template_name = 'ecoke/feedback.html' | |
def get_initial(self): | |
if self.request.user.is_authenticated(): | |
return { | |
'name': self.request.user.profile.get_screen_name, | |
'email': self.request.user.email, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def _generate_cart_id(): | |
cart_id = '' | |
characters = 'ABCDEFGHIJKLMNOPQRQSTUVWXYZabcdefghiklmnopqrstuvwxyz1234567890!@#$%^&*()' | |
cart_id_length = 50 | |
for y in range(cart_id_length): | |
cart_id += characters[random.randint(0, len(characters)-1)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# List unique values in a DataFrame column | |
# h/t @makmanalp for the updated syntax! | |
df['Column Name'].unique() | |
# Convert Series datatype to numeric (will error if column has non-numeric values) | |
# h/t @makmanalp | |
pd.to_numeric(df['Column Name']) | |
# Convert Series datatype to numeric, changing non-numeric values to NaN | |
# h/t @makmanalp for the updated syntax! |
OlderNewer