每天推薦一個 GitHub 優質開源項目和一篇精選英文科技或編程文章原文,歡迎關注開源日報。交流QQ群:202790710;電報群 https://t.me/OpeningSourceOrg


今日推薦開源項目:《Django——強大的python web框架

推薦理由:Django是一個基於Python的開源web應用框架,採用了MT』V的框架模式,他源自一個在線新聞web站點,以比利時的一個柬埔寨吉他手的名字命名(他的曲子真的很不錯)。Django不算很年輕,但是對於一個web開發者,深入學習Django,永遠都不會過時。

 

安裝(Windows下):

在安裝Django框架之前你的PC需要有一個Python環境,Python環境並不難搭建,就不在此過多贅述。

搭建好Python環境後,直接在官網的下載欄下載即可(點擊此處下載)(目前Django1.6.x以上版本已經完全兼容Python3.x)。下載好安裝包後,加壓並和Python安裝目錄放在同一個根目錄,進入Django目錄。

在此目錄下打開終端,並執行python setup.py install,然後開始安裝,Django將要被安裝到Python的Lib下site-packages。

最後是配置環境變數,將目錄添加到系統環境變數當中即可。完成後就可以使用Django的django-admin.py命令新建工程了。

開始你的Django之旅:

創建django項目:

使用 django-admin.py 來創建一個名為mysite的項目:

django-admin.py startproject mysite

創建完成後,通過manage.py啟動django自帶的伺服器:

python manage.py runserver

默認在127.0.0.1:8000啟動服務,訪問該地址顯示以下頁面表示創建成功:

創建新的app:

創建完項目後,在mysite目錄下創建一個名為HelloDjango的app:

python manage.py startapp HelloDjango

創建完成後目錄結構如下:

HelloDjango/

__init__.py

admin.py

migrations/

__init__.py

models.py

tests.py

views.py

創建完成後在setting.py中找到INSTALLED_APPS,輸入『HelloDjango』

設計你的模型:

Django一個比較方便的地方是它附帶了一個可以用Python代碼描述資料庫布局的對象關係映射器,數據模型語法提供了許多豐富的方法來展現你的模型。

創建一個包含title,content,pub time的模型:

models.py:

from django.db import models
class Article(models.Model):
    title = models.CharField(max_length=32,default='Title')
    content = models.TextField(null=True)
    pub_time = models.DateTimeField(auto_now_add=True)

創建完成後同步資料庫:

python manage,py makemigrations
python manage.py migrate

並在admin.py中註冊:

from django.contrib import admin
from .models import Article
admin.site.register(Article)

Admin 管理工具

Django 最強大的部分之一是自動生成的Admin 界面。它讀取模型中的元數據來提供一個強大的、生產環境就緒的界面,使內容提供者能立即用它向站點中添加內容。你可以通過 python manage.py createsuperuser創建管理員賬號,通過127.0.0.1:8000/admin訪問Admin界面。

你可在settings.py中將Admin界面的語言和時間設置為中國

LANGUAGE_CODE = 'zh-hans'

TIME_ZONE = 'Asia/Shanghai'

在Admin界面中你可訪問並管理之前註冊的Article模型,如添加一篇新的內容:

前端頁面

Django的前端頁面保存在Templates文件夾中,在HelloDjango中新建Templates文件夾並編寫自己的前端代碼。圖片等資源則需要保存在static文件夾中

配置url與views

我們可以為每個app單獨配置url,

  • 首先配置mysite中的urls.py
from django.contrib import admin
from django.urls import path
from django.urls import include
urlpatterns = [
    path('admin/', admin.site.urls),
    path('HelloDjango/',include('HelloDjango.urls')),
]
  • 在HelloDjango中新建urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
    url(r'^$',views.index),
]
  • 在views.py中
from django.shortcuts import render
from . import models
def index(request):
    return render(request,'index.html')

此時訪問http://127.0.0.1:8000/HelloDjango則會顯示自己編寫的index.html的內容

如:

在網頁中載入資料庫中的內容:

  • 在views.py中載入:
def Article(request,Article_id):
    article = models.Article.objects.get(pk=Article_id)
    return render(request,'article.html',{'article':article})
  • 在urls.py中添加:
url('article/(?P<Article_id>[0-9]+)$', views.Article)
  • 在article.html中通過{{article.title}},{{article.content}},{{article.pup_time}}可以分別載入出文章的標題,內容,時間(對應自己創建的模型)

完成後通過『127.0.0.1:8000/HelloDjango/article/』 + 文章的id 就可以訪問指定的文章

如127.0.0.1:8000/HelloDjango/article/1 訪問新建的第一篇文章:

了解更多,歡迎訪問(別著急,後面有彩蛋)

GitHub:https://github.com/django/django

官網: https://www.djangoproject.com/

 

彩蛋:

關於吉他手Django Reinhardt

法國著名吉他手,爵士樂史上的偉大琴師。1910年出生於比利時,

因18歲時一次意外導致只能以三個健全手指進行演奏,但仍然創造了傳世的音樂作品

和令人讚歎的成就。1953年在法國去世。


今日推薦英文原文:《Becoming a 10x Developer》作者:Kate Heddleston

原文鏈接:https://kateheddleston.com/blog/becoming-a-10x-developer

推薦理由:這篇文章的副標題其實叫做 10 Ways to be a Better Teammate;成為一個好搭檔的10種方法。一個好的球星不僅自己是一個很棒的球員,同時也一定是一個很好的助攻,以團隊協作來看,好的搭檔可謂難得,現在的軟體工程以及開源協作都對互相配合提出了很高的要求,好的互助事半功倍、互相拆台則事倍功半,不僅學會自己成為一個好程序員,同時學會成人之美,成為一個好的搭檔,也各位重要。

Becoming a 10x Developer

When I was first learning to play water polo, a coach told me something I』ve never forgotten. He said, 「Great players make everyone around them look like great players.」 A great player can catch any pass, anticipating imperfect throws and getting into position. When they make a return pass, they throw the ball so that the other person can make the catch easily.

Software engineering today is a team sport; like water polo, you can』t build incredible software systems alone. So when I first heard the concept of the 10x engineer, I was confused. How could someone be so talented that it overshadows the power of teamwork? In my experience, individual excellence is necessary, but not sufficient, for greatness. Focusing purely on individual achievement misses the larger picture that teams are required to build great software. So I decided to change the definition of a 10x engineer to this:

A 10x engineer isn』t someone who is 10x better than those around them, but someone who makes those around them 10x better.

Over the years I』ve combined my personal experience with research about building and growing effective teams and turned that into a list of 10 ways to be a better teammate, regardless of position or experience level. While many things on this list are general pieces of advice for how to be a good teammate, there is an emphasis on how to be a good teammate to people from diverse backgrounds.

10 Ways to be a Better Teammate

  1. Create an environment of psychological safety
  2. Encourage everyone to participate equally
  3. Assign credit accurately and generously
  4. Amplify unheard voices in meetings
  5. Give constructive, actionable feedback and avoid personal criticism
  6. Hold yourself and others accountable
  7. Cultivate excellence in an area that is valuable to the team
  8. Educate yourself about diversity, inclusivity, and equality in the workplace
  9. Maintain a growth mindset
  10. Advocate for company policies that increase workplace equality

1. Create an environment of psychological safety

In 2012, Google launched Project Aristotle to study hundreds of Google teams and figure out why some teams performed better than others [1]. The study found that there were only two key differences between more productive teams and less productive teams. One of those two the key components was something researchers call Psychological Safety. Harvard Business School professor Amy Edmondson described it as a 「shared belief held by members of a team that the team is safe for interpersonal risk-taking」 and 「a sense of confidence that the team will not embarrass, reject or punish someone for speaking up.」 [1] Creating an environment of psychological safety creates a space where team members can trust one another and share their opinions and ideas about work freely. Here are some ways to foster an environment of psychological safety within your own workplace.

  1. Acknowledge people』s ideas and feelings in a non-judgemental way. Acknowledgment is a separate step from judging or assessing.
  2. Respond to ideas with a 「yes and」 attitude to build off what your teammates say (like in improvisational comedy!) [2].
  3. Give people the benefit of the doubt. Believe them until proven otherwise, as opposed to making them prove themselves until you believe them.

2. Encourage everyone to participate equally

Project Aristotle, the research study on effective teams at Google [1], found one other important component for productive teams. It』s a phenomenon that the academic world has named 『『equality in distribution of conversational turn-taking.』』 Basically, this just means that people on effective teams participate equally. This doesn』t mean that people have to speak equally in every meeting, but that, over time, everyone on a team will contribute equally. So how can you foster a team culture in which everyone participates equally?

  1. Ask people their opinions in meetings.
  2. Invite discussion with your language by using words like 「I think」 and 「maybe」. (I call this conversational style: "Maybe you should talk more like a woman?")
  3. Communicate frequently and informally [3].
  4. Notice when someone else might be dominating a conversation and make room for others to speak.

3. Assign credit accurately and generously

Giving credit to people accurately for their work is an important part of establishing trust in a team and organization [4]. Many of us have had a personal experience where we felt like we didn』t receive credit for our work, or credit was given to the wrong person.

One of the great things about giving other people credit is that it doesn』t just make the other person look good, it also makes you look good. People who acknowledge others are seen as both smarter and more likable by other people. Basically, it』s a win-win and there』s no reason to hold back in your praise of others.

What can you do to help foster a culture where people assign credit to others for their work?

  1. Make sure you take time at the end of each project to thank the people who helped you.
  2. Especially try to notice people who are quiet and don』t do much self-promotion, or people who are new and lack confidence.
  3. Be honest, specific, and genuine when assigning credit and praising others』 work.

4. Amplify unheard voices in meetings by repeating what they say

None

In 2009, a group of President Obama』s female staff banded together and devised a strategy they called 「amplification」 [5]. They were experiencing a lot of the things women face in male-dominated workplaces—they were having trouble getting into important meetings and, when there, were often overlooked or unheard. So they would amplify each other』s voices. When a female staffer made a key point, the other women would repeat it and give credit to the author, which forced everyone to notice where the idea came from. President Obama himself noticed this and made a point to call on more female staffers more. By his second term, there was an even gender split and half the departments were headed by women.

This is such a simple, concrete thing that any person on any team can do for their teammates. Notice when people are overlooked or unheard and amplify what they say. While it』s common for women to be spoken over [6], it can also happen to people who are soft-spoken, shy, or introverted.

5. Give constructive, actionable feedback and avoid personal criticism

People pretty universally dislike being criticized and, when not given thoughtfully or constructively, criticism can actually damage people』s performance [8]. I've talked about this before, but making sure that your feedback is thoughtful and constructive is a really important way you can be a great teammate. Additionally, the way we give feedback can be biased, so spending time learning to give feedback well is important for diverse teams.

For example, there』s a common perception that women receive criticism that men don』t. Women report being called 「bossy」, 「pushy」, and 「aggressive」 more than their male peers. In 2014, Kieran Snyder, founder and CEO of Textio, decided to test that idea [7]. She collected 248 reviews from 180 people, 105 men and 75 women, and analyzed the contents of those reviews. What she found was surprising, even if you know it』s there. Of the women』s reviews, 87.9% percent contained criticism or negative feedback as opposed to 58.9% of men. Furthermore, the criticism given to men and women wasn』t the same. Of the criticism women received, 76% of it was personal in nature as opposed to 2% of criticism given to men.

Here are some ways you can give better feedback.

  1. Ask people if they』re open to feedback before giving feedback.
  2. Focus your feedback on the person』s work as much as possible.
  3. Tell people how they can make things better. Clearly identify the issue as you see it and explain how you think the person can make things better.
  4. Avoid personal criticism. If you feel that you need to give someone feedback on their person, work with a manager or HR to make sure that you have your thoughts organized.

6. Hold yourself and others accountable

Recently I met with a friend of mine, James, who was a football player in college. He』s now the COO of a startup, and he mentioned that he was spending a lot of his time teaching what he considered basic teamwork to employees, especially around accountability. As I thought about it more, I realized that James has spent thousands and thousands of hours practicing being a good teammate. Things that are obvious to him about working well as a team might not be obvious to others, especially when it comes to accountability. Football has a strong culture of accountability, and some of the ways football players hold each other accountable are through being on time to practice, having a positive attitude, encouraging teammates, and holding each other to a standard of excellence. Here are some ways you can hold yourself and others accountable.

  1. Get your work done as on-time as you can (I know as engineers estimates are one of our biggest challenges, but smaller projects with more accurate estimates help foster accountability).
  2. Jeff Lawson once told a group of founders that the most important thing is 「doing what you say you』ll do」.
  3. Help others, and ask for help when you need it.
  4. For big projects or issues, stay present until your team』s work is finished [9] (whether that presence is in-person or through remote tools like Slack).

7. Cultivate excellence in an area that is valuable to the team

When we talk about being a 10x engineer, this is usually what people are referring to—individual excellence. Individual excellence is a necessary part of being a good teammate. After all, you need to do something for your team. What you choose to become excellent at is really about what motivates you; it should be something that gives you energy and fits your skills and interests. Excellence takes a lot of time and energy to cultivate, especially as our individual knowledge base is becoming more and more specialized [10], so pick something you enjoy doing because you'll probably be at this a while. I feel that individual excellence is harped on a lot in our society, so I』ll let you read the slew of self-help books and blog posts out there on how to be more excellent at your craft.

8. Educate yourself about diversity, inclusivity, and equality in the workplace

None

Diversity and Inclusion is a team sport—we need everyone at every level to participate. One of the number one things you can do to be a good teammate is to educate yourself about how gender and race discrimination take form in the workplace. In the same way that you need to stay educated on programming languages and tooling, it』s important to stay up to date on all the amazing writing and research about how to create more egalitarian work environments.

There is a joke that 「behind every woke man is an exhausted feminist」, and probably behind every woke white person is an exhausted person of color. Let』s change that. Anyone can read and do research.

  1. Read everything
  2. Ask people for reading suggestions or join mailing lists
  3. Listen as much as you can
  4. Your opinion is as valuable as your education, so if you have not educated yourself, your opinion is not valuable.

9. Maintain a growth mindset

Thirty years ago, psychologist Carol Dweck was interested in the concept of failure and resilience [11]. She and her research team noticed that some students rebounded from failure while others were demoralized even by small setbacks. She wanted to know why. After studying thousands of children, she coined the term Growth Mindset, which refers to the belief that abilities and intelligence can be developed. Students who believe that they can increase their abilities and intelligence rebound from failure, while students who believe intelligence is fixed are more likely to be demoralized by setbacks.

  1. Remember you can learn anything given time, effort, and the internet.
  2. Be prepared for feedback on how you can improve.
  3. There is no finish line; being a great engineer and a great teammate is a lifelong, daily practice.

10. Advocate for companies policies that increase workplace equality

None

Finally, speak up about ways you think your company can create a more egalitarian, inclusive workplace for every member of your team. No matter what your level within the organization, you can advocate for policies that will improve your work environment. Reading and doing research per recommendation #8 will make this step a lot easier. Some examples of organizational changes that have proven effects are:

  1. The Rooney Rule: for any key position, you have to interview at least one person of color for the role [12]
  2. Evaluate candidates in groups for promotions [13]
  3. Making meetings, salaries, key initiatives, and internal processes more transparent.

 


每天推薦一個 GitHub 優質開源項目和一篇精選英文科技或編程文章原文,歡迎關注開源日報。交流QQ群:202790710;電報群 https://t.me/OpeningSourceOrg