title: Django: How do I include username in url?
body: <p>Django2.1</p>
  
  <p>My application wants to include twitter username in url, but an error occurs.
  I can get uesrname correctly, but I can not connect to url correctly.
  What is the cause?</p>
  
  <p>An error occurs when accessing detail.</p>
  
  <pre><code>ValueError at /Temporary username/detail
  invalid literal for int() with base 10: 'Temporary username'
  </code></pre>
  
  <pre><code>#views.py
  class MyDetailView(DetailView):
      model = Mymodel
  
  class MyCreateView(LoginRequiredMixin, CreateView):
      model = Mymodel
      form_class = MyForm
  
      def form_valid(self, form):
          obj = form.save(commit=False)
          obj.user = self.request.user
          return super(MyCreateView, self).form_valid(form)
  
      def get_success_url(self):
          return reverse_lazy('detail', kwargs={"pk": self.request.user.username})
  </code></pre>
  
  <pre><code>#urls.py
  urlpatterns = [
      path('&lt;slug:pk&gt;/detail', MyDetailView.as_view(), name="detail"),
      path('create/', MyCreateView.as_view(), name="create"),
  ]
  </code></pre>
  
  <p>Thank you</p>