The main purpose of this operation is to jump to the userinfo page by clicking userid for user-related information:
1: View personal information page:
On the personal information page, there are two columns of information: one column is the information of the current user and the other column is the information of the user to be compared. When performing a jump, the principle is: Put the information of the clicked user in the column on the right for use on the page.
The user object is other. Put the information of the current user in the left column, which corresponds to the user on the page.
2: Execute the modification:
2.1: Test
First, in order not to affect the operation of OJ, I have created a copy version user of userinfo and the copy version user of userinfo URL as the test file.
First, execute the URL of the user page to execute
2.2: Modify links and views
The URL of the existing userinfo page is passed without parameters. We need to add the user ID after this URL to pass it.
Modified URL
url(r'^user/(?P<user_id>\d+)$', views.user, name = 'user'),
Here, the user_id is the user ID to be passed in, and D + represents an integer (W + is changed later, and the unique ID can be passed in ). View. User is implemented in view similar to a control method, that is, to receive the user ID and
Take this ID to find the user to generate the other user we need.
def user(request, user_id): try: user = User.objects.get(userID = request.session['userID']) except: return HttpResponseRedirect("/index/login") other = User.objects.get(userID = user_id) if request.method == 'POST': userID = request.POST['userID'] oldPassword = request.POST['oldPassword'] password = request.POST['password'] confirmPassword = request.POST['confirmPassword'] session = request.POST['session'] specialty = request.POST['specialty'] tel = request.POST['tel'] email = request.POST['email'] nickname = request.POST['nickname'] if oldPassword != user.password: return HttpResponse("password error") else: if password.strip() != '' and password == confirmPassword: user.password = password user.session = session user.specialty = specialty user.tel = tel user.email = email user.nickname = nickname user.save() return render(request, 'cugbacm/userInfo.html', {'userID':request.session['userID'],'user': user, 'other':other}) else: return HttpResponse("password and confirmPassword is not the same!") else: return render(request, 'cugbacm/userInfo.html', {'userID':request.session['userID'],'user': user, 'other':other})
Here we can see that we receive the parameter user_id from the URL to form our other, and then pass the other user to the userinfo page in the render. The judgment here is to modify the user's new Personal Information
Save. Not solved yet.
2.3: Modify the link on the page
Here, the href link of the user ID in the HTML file is changed to "/index/userinfo/ID to be passed ". For example, if you want to modify all the users involved, add a link to the user ID.
Connection:
<ul class="dropdown-menu"> <li><a href="/index/userInfo/{{userID}}">User Info</a></li> <li><a href="#">Another action</a></li> <li><a href="#">Something else here</a></li> <li class="divider"></li> <li><a href="/index/login">Login out</a></li> </ul>
Among them, {userid} is the parameter we need to pass.
2.4: Page Test
Restart the server and check the implementation of the modified functions.
3: modify the original userinfo:
I thought it would be okay to copy the user in the view to the userinfo in the view. A lot of errors have been reported, and it has been called for a long time.
First, click User Info in userinfo to jump to userinfo. As discussed above, you only need to set the passed parameter to the ID of the current user. However, it is always wrong. Upload
When the parameter is passed, we can honestly say 404 notfound. The main thing is that no ID is passed in the URL link. It's strange that the ID of the current user is not displayed, in addition, parameters are added to the URL. Various
The code below is found:
return render(request, 'cugbacm/user.html', {'userID':request.session['userID'],'user': user, 'other':other})
Again, I wrote the user.html file first. After the modification, it seems that I can. However, at this time, the server does not respond to the changes to the page, and all kinds of calls do not respond. After a while, the server will die. Restarted
Computer, wait for a moment to connect, and then respond again, can't stand it. Then, we changed the next link and it was OK. Then, modify all the other related IDs.
4: Test
The conversion of userid to userinfo is basically changed on every page. It's all about href modification. Basically, all the basic needs are acceptable.
In general, there is basically no code volume, that is, repair, modification, and modification. At the beginning, I kept reading the process of the entire OJ page to understand the basic process. There are some imitation repairs, modifications, and changes. Too frustrating, with no logic
Clearly, there is also the way in which I modified the URL transmission parameters, which needs to be modified in many places, such as personal information modification. In fact, this was not taken into account at the time. Now it is also a troublesome task, and it needs to be modified later.