import requests from django.shortcuts import render, redirect from django.contrib.auth.forms import UserCreationForm from django.contrib.auth import login from django.http import JsonResponse def index(request): return render(request, 'blog_app/index.html') def weather_data(request): api_key = "00eb2155e51742aa2856a69da0f6dc61" # OpenWeather에서 발급받은 API 키 city = "Seoul" url = f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric&lang=kr" weather = {} try: response = requests.get(url) data = response.json() weather = { 'city': city, 'description': data['weather'][0]['description'], 'icon': data['weather'][0]['icon'], 'temperature': data['main']['temp'], } return JsonResponse(weather) except Exception as e: return JsonResponse({'error': str(e)}, status=500) def signup(request): if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): user = form.save() login(request, user) return redirect('index') else: form = UserCreationForm() return render(request, 'blog_app/signup.html', {'form': form}) def about(request): return render(request, 'blog_app/about.html') def post(request): return render(request, 'blog_app/post.html') def contact(request): return render(request, 'blog_app/contact.html')