Add simple views

parent 0a6764d6
......@@ -17,5 +17,6 @@ from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^', include('urlforward.urls')),
url(r'^admin/', include(admin.site.urls)),
]
from django.contrib import admin
# Register your models here.
from .models import Url
admin.site.register(Url)
<h1>Details of URL {{ url.id }}</h1>
<ul>
<li>Owner: {{ url.user.first_name }} {{ url.user.last_name }}
({{ url.user.username }})</li>
<li>Target: <a href="{{ url.target }}" target="_blank"><code>{{ url.target }}</code></a></li>
<li>Followed: {{ url.used }} time(s).</li>
</ul>
<h1>List of URLs</h1>
{% if url_list %}
<ul>
{% for u in url_list %}
<li>
<a href="/url={{ u.id }}">Show details</a>, or follow
<a href="/{{ u.id }}" target="_blank"><code>{{ u.target }}</code></a>
</li>
{% endfor %}
</ul>
{% else %}
<p>No URLs are available.</p>
{% endif %}
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^(?P<url_id>[0-9]+)$', views.redir, name='redir'),
url(r'^url=(?P<url_id>[0-9]+)$', views.details, name='details'),
]
from django.shortcuts import render
from .models import Url
# Create your views here.
def index(request):
context = {
'url_list': Url.objects.all()
}
return render(request, 'index.html', context)
def redir(request, url_id):
return HttpResponse("You are following the url: {}".format(url_id))
def details(request, url_id):
context = {
'url': Url.objects.get(id=url_id)
}
return render(request, 'details.html', context)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment