-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathviews.py
44 lines (27 loc) · 1.24 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from django.shortcuts import render
from .models import ProgrammingLanguage, Documentation
from django.shortcuts import get_object_or_404, redirect
from django.http import JsonResponse
def home(request):
languages = ProgrammingLanguage.objects.all()
return render(request, 'home.html', {'languages': languages})
def documentation_list(request, language_id):
language = ProgrammingLanguage.objects.get(id=language_id)
docs = Documentation.objects.filter(language=language)
return render(request, 'docs_list.html', {'language': language, 'docs': docs})
def search_language(request):
query = request.GET.get('name', '')
if query:
languages = ProgrammingLanguage.objects.filter(name__icontains=query)
if languages.exists():
language = languages.first()
return redirect(language.official_website)
return JsonResponse({'error': 'No programming language found'}, status=404)
def about(request):
return render(request, 'html/about.html')
def contact(request):
return render(request, 'html/contact_us.html')
def programming_languages_info(request):
return render(request, 'programming_languages_info.html')
def tutorials(request):
return render(request, "tutorials.html")