1

我有项目,我必须将我的项目部署到服务器。在本地,我的项目可以正常工作。但是,当我尝试在服务器中运行时。为什么会出现这个错误

环境:

Request Method: GET
Request URL: http://www.cs.ui.ac.id/profil/a_lihat_riwayat_publikasi/1

Django Version: 1.7.4
Python Version: 2.7.3
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Template error:
In template /home/rangga/profil/profil_apps/templates/a_lihat_riwayat_publikasi.html, error at line 10
   Reverse for 'a_tambah_riwayat_publikasi' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['profil/a_tambah_riwayat_publikasi/(?P<pk>\\d+)$']
   1 : {% extends "base.html" %}


   2 : {% block content %}


   3 : <section id="main-content">


   4 :   <section class="wrapper">


   5 :    <div class="row mt">


   6 :     <div class="col-md-12">


   7 :       <div class="content-panel">


   8 :         <ul class="nav pull-right top-menu">


   9 :           <ul class="nav pull-right top-menu">


   10 :             <li><a class="logout" href=" {% url "a_tambah_riwayat_publikasi" userid.pk %} " style="font-size:100%; color:black;"><b>Tambah Riwayat Publikasi</b></a></li>


   11 :           </ul>


   12 :         </ul>


   13 :         <table class="table table-striped table-advance table-hover">


   14 :           <h4><i class="fa fa-angle-right"></i> Lihat Riwayat Publikasi</h4>


   15 :           <hr>


   16 :           <thead>


   17 :             <tr>


   18 :               <th>No</th>


   19 :               <th>Tahun</th>


   20 :               <th>Nama_Dosen</th>


Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/rangga/profil/profil_apps/profil/views.py" in a_lihat_riwayat_publikasi
  425.                 return render(request, 'a_lihat_riwayat_publikasi.html',)
File "/usr/local/lib/python2.7/dist-packages/django/shortcuts.py" in render
  50.     return HttpResponse(loader.render_to_string(*args, **kwargs),
File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py" in render_to_string
  174.         return t.render(context_instance)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render
  148.             return self._render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in _render
  142.         return self.nodelist.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render
  844.                 bit = self.render_node(node, context)
File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py" in render_node
  80.             return node.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py" in render
  126.         return compiled_parent._render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in _render
  142.         return self.nodelist.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render
  844.                 bit = self.render_node(node, context)
File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py" in render_node
  80.             return node.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py" in render
  65.                 result = block.nodelist.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render
  844.                 bit = self.render_node(node, context)
File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py" in render_node
  80.             return node.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py" in render
  458.                         six.reraise(*exc_info)
File "/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py" in render
  444.             url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in reverse
  551.     return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _reverse_with_prefix
  468.                              (lookup_view_s, args, kwargs, len(patterns), patterns))

Exception Type: NoReverseMatch at /profil/a_lihat_riwayat_publikasi/1
Exception Value: Reverse for 'a_tambah_riwayat_publikasi' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['profil/a_tambah_riwayat_publikasi/(?P<pk>\\d+)$'] 

这是我的网址:

url(r'^a_tambah_riwayat_publikasi/(?P<pk>\d+)$', views.a_tambah_riwayat_publikasi, name='a_tambah_riwayat_publikasi'),
url(r'^a_lihat_riwayat_publikasi/(?P<pk>\d+)$', views.a_lihat_riwayat_publikasi, name='a_lihat_riwayat_publikasi'),

这是我的看法:

def a_lihat_riwayat_publikasi(request, pk):
    if 'username' in request.session:
        if request.session['hak_akses'] == 'humas':
            try:
                username_session = request.session['username']
                hak_akses_session = request.session['hak_akses']
                userid = get_object_or_404(Dosen, pk = pk)
                publikasi = DosenPublikasi.objects.select_related().filter(userid=userid.userid)
                data = {
                        'userid': userid,
                        'object_list':publikasi,
                        'username':username_session,
                        'hak_akses':hak_akses_session,
                        'link':'manajemen_profil',
                }
                return render(request, 'a_lihat_riwayat_publikasi.html', data)
            except:
                return render(request, 'a_lihat_riwayat_publikasi.html',)
    else:
        return HttpResponseRedirect('/profil/login')

这是我的 HTML 模板:

<ul class="nav pull-right top-menu">
  <li><a class="logout" href="{% url "a_tambah_riwayat_publikasi" userid.id %}" style="font-size:100%; color:black;"><b>Tambah Riwayat Publikasi</b></a></li>
</ul>

我的问题

  1. 我认为我的语法没有错误,但是为什么会发生这个错误?

  2. 解决方案如何?

4

0 回答 0