我一直在尝试编写一个python代码,它会自动从我的选择属性(drf)中给我一个列表
看起来像这样:
2011/2012
2012/2013
2013/2014
2014/2015
2015/2016
...
但我残忍地失败了。 下面是我的代码(没有做任何合理的事情)
x = xrange(2011, 2015)
y = xrange(2012, 2016)
z = '%5d / %5d' % (x, y)
print '\n'.join(z)
感谢帮助人员。 还有一件事 所以我试着在我的drf模型中输入我的选择属性,除了当我把
时,它没有给我任何错误消息Print z
它包括我运行时服务器控制台中的输出
Python manage.py runserver
这是我下面的代码,我想确定我做的是正确的
class studentship(models.Model):
def datechoice():
x = xrange(2011,2016)
y = xrange(2012,2017)
for tup in zip(x,y):
z = '%d/%d' %(tup[0], tup[1])
pick_date = (datechoice())
enroll = models.Charfield(max_Length = 1, choices =
pick_date, default = 'select school session')
谢谢你的帮助,我保证会急忙改进我的python。
答案 0 :(得分:1)
您不能使用字符串格式来获取字符串列表。你必须明确地写一个for循环:
class SubsController extends Controller
{
public function store(Request $request)
{
$newsubscriber = new Subscriber;
$newsubscriber->email = $request->input('email');
$newsubscriber->save();
}
}
答案 1 :(得分:0)
虽然,你的问题有点不清楚,试试这个:
for x in range(2011, 2016):
print("{}/{}".format(x, x+1))
输出:
2011/2012
2012/2013
2013/2014
2014/2015
2015/2016
答案 2 :(得分:0)
将每个范围增加一年
com.androchunk.splash_screen E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.androchunk.splash_screen, PID: 3656
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.androchunk.splash_screen/com.androchunk.splash_screen.Splash_Activity}: android.view.InflateException: Binary XML file line #0: Error inflating class ImageView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2455)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2519)
at android.app.ActivityThread.access$800(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:189)
at android.app.ActivityThread.main(ActivityThread.java:5532)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class ImageView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.androchunk.splash_screen.Splash_Activity.onCreate(Splash_Activity.java:13)
at android.app.Activity.performCreate(Activity.java:5966)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2408)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2519)
at android.app.ActivityThread.access$800(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:189)
at android.app.ActivityThread.main(ActivityThread.java:5532)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
Caused by: android.content.res.Resources$NotFoundException: Resource "com.androchunk.splash_screen:drawable/androchunk" (7f060054) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f060054 a=-1 r=0x7f060054}
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2596)
at android.content.res.Resources.loadDrawable(Resources.java:2536)
at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
at android.widget.ImageView.<init>(ImageView.java:146)
at android.widget.ImageView.<init>(ImageView.java:135)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:72)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:68)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1024)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1081)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.androchunk.splash_screen.Splash_Activity.onCreate(Splash_Activity.java:13)
at android.app.Activity.performCreate(Activity.java:5966)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2408)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2519)
at android.app.ActivityThread.access$800(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:189)
at android.app.ActivityThread.main(ActivityThread.java:5532)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
at com.android.internal